Turning on suggestions for new issues
The reactive forms API contains a mechanism for getting notified when the value of a particular form control changes. We will use it in our application to find related issues when reporting a new one. More specifically, we will display a list of suggested issues when the user starts typing in the title form control:
- Open the
issues.service.ts
file and add the following method:getSuggestions(title: string): Issue[] { if (title.length > 3) { return this.issues.filter(issue => issue.title.indexOf(title) !== -1); } return []; }
The preceding method takes the title of an issue as a parameter and searches for any issues that contain the same title. The search mechanism is triggered when the
title
parameter is more than three characters long to limit results to a reasonable amount.
- Open the
issue-report.component.ts
file and import theOnInit
artifact from the@angular/core
npm package...