Currently, I am facing an issue with two components in my Angular project - HomePageComponent and StudentResultsComponent. The problem arises when I type something in the input field of HomePageComponent; the value is not updating in the StudentResultsComponent as expected.
I initially considered creating a separate component for the input and then calling it in both components to resolve the issue. However, even after implementing this approach, the value was still not being updated in the StudentResultsComponent while typing in HomePageComponent.
Here is a snippet of 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 primary reason behind passing data from the homepage component is so that I can utilize this data for querying and displaying results based on the values obtained from the other component.
Your assistance in resolving this issue would be greatly appreciated.
Thank you.