Hi i am new in angular 2/4.I Need to highlight the word that is been searched, while displaying the result (the key word searched will be in bold in the search results). And During searching, ‘as-you-type’ suggestion to be displayed.Like This Google image here.
this is my Component.ts
DetailsSearch(itemcode: string): void {
this.searchflag = 1;
this.pageIndex = 1;
this.prevScrollPosition = 0;
if (itemcode.length > 0) {
this.searchcontent = itemcode;
}
else {
itemcode = undefined;
this.searchcontent = itemcode;
}
this._Service.DetailsSearch(this.searchcontent, this.pageIndex).subscribe(itemsData => this.itemdetails = itemsData,
error => {
console.error(error);
this.statusMessage = "Problem with the service.Please try again after sometime";
});
}
this is my html
<form role="form">
<div class="row">
<div class="form-group">
<div class="input-group">
<input class="form-control" type="text" name="search" placeholder="Search" required="" [(ngModel)]='searchcontent'>
<span class="input-group-btn">
<button class="btn btn-danger ProductSearchBtn" type="button" (click)='DetailsSearch(searchcontent)'><i class="glyphicon glyphicon-search" aria-hidden="true"></i><span style="margin-;">Search</span></button>
</span>
</div>
</div>
</div>
</form>
If you want to create Type ahead Search in angular try to use reactive form
Check the below Blog https://codecraft.tv/courses/angular/http/http-with-observables/