html - How can call a function in service on click event in angular2? -
this working plunker : http://plnkr.co/edit/fojhoflsglrb4po5li6b?p=preview . on clicking classes corresponding content @ bottom changes, hardcoded & possible have makes content come service :
export class subjectservice { getclass(id : number) : { if(id==15) return [{label: 'science', state: false},{label: 'computer science', state: false},{label: 'social science', state: false},{label: 'environmental studies', state: false}]; else if (id==68) return [{label: 'english', state: false},{label: 'hindi', state: false},{label: 'mathematics', state: false},{label: 'science', state: false}]; else if (id==910) return [{label: 'english', state: false},{label: 'hindi', state: false}{label: 'social science', state: false},{label: 'sanskrit', state: false}]; else return [{label: 'english', state: false}{label: 'pol science', state: false},{label: 'comp science', state: false},{label: 'social science', state: false}]; } }
i have small angular 2 app created calling service on click. please see source code here of github. can see heroservice.ts in app/services folder , heroes.component.ts.
repository: https://github.com/khanstudio-github/angular2appaspnet/tree/master/angular2starterapp/angular2starterapp
i hope you. please feel free ask if facing issue.
Comments
Post a Comment