I have two components HomePageComponent and StudentResultsComponent. I have an input in HomePageComponent that when I type, I want the value to be in my StudentResultsComponent input.
I thought of creating a separate component for the input and calling them in both components, but the value is not being updated in my StudentsResultsComponent when I start typing in HomePageComponent. Heres my code:
Career-Search-Component.html
<input
#input
type ="text"
id ="searchInput"
class ="input-student-search validate filter-input"
placeholder ="Search by a career (Software Engineer,Web Developer,Geologist, Geogropher etc.)"
[(ngModel)] ="query"
>
Career-Search.component.ts
import {Component,OnInit,Input,EventEmitter} from '@angular/core';
@Component({
selector: 'career-search',
templateUrl: 'career-search.component.html'
})
export class CareerSearchComponent implements OnInit {
@Input() public query: string;
constructor() {}
ngOnInit() {}
}
HomePageComponent.component.html
<career-search></career-search>
<button class="submit" [routerLink]="['/students']">Search</button>
Students-result.component.html
<career-search></career-search>
The reason why i need to pass the data from the homepage component is because I can then use the data to query it and show results based on the value being passed from the other component.
Please help.
Thanks
HomePageComponentand pass it to my input inside another component calledStudentResultsComponentusing ngModel @AJT_82Input()if they are not parent and child, you need to use a shared service :)