We have been facing a problem of passing the event from the html to one of the Javascript methods that requires it.
export class SearchComponent implements OnInit {
txtQueryChanged: Subject<string> = new Subject();
constructor(private AService: AService, public _router: Router, location: PlatformLocation) {
this.txtQueryChanged.debounceTime(1000)
.distinctUntilChanged()
.subscribe(model => {
this.q = model;
// Call function which calls API after a lag of 1 sec
this.getDetails(model);
});
}
watchChangesInSearchTerm(query: string, $event:
this.txtQueryChanged.next(query);
}
getDetails(event: any) {
this.eventKey = event.which;
if (this.q.trim() == "") {
this.closeSearch();
}
// other programming logic including the API call
}// end of function
}// end of class
now the HTML that calls this watchChangesInSearchTerm is as follows
<input type="text" class="searchfield" [(ngModel)]="q" name="searchfield" (keyup)="watchChangesInSearchTerm(q, $event)" placeholder="What are you searching for today?">
Now the code from the HTML calls the watchChangesInSearchTerm method but it only passes the searchString int he parameter. The watchChangesInSearchTerm in turns debounces the model and calls the getDetails method. This method is also called for so many other use cases as well and thus requires the event through which it is triggered.
How can we pass the event to the getDetails method?