import { Injectable } from '@angular/core' ; import { issues } from '../assets/mock-issues' ; import { Issue } from './issue' ; @ Injectable ( { providedIn : 'root' } ) export class IssuesService { private issues : Issue [ ] = issues ; constructor ( ) { } getPendingIssues ( ) { return this . issues . filter ( issue => ! issue . completed ) ; } createIssue ( issue ) { issue . issueNo = this . issues . length + 1 ; this . issues . push ( issue ) ; } completeIssue ( issue ) { const selectedIssue = { ... issue , completed : new Date ( ) } ; const index = this . issues . findIndex ( i => i === issue ) ; this . issues [ index ] = selectedIssue ; } getSuggestions ( title ) { if ( title . length > 3 ) { return this . issues . filter ( issue => issue . title . indexOf ( title ) !== - 1 ) ; } return [ ] ; } }