Angular: Giving a component field a reference to a service function and calling it from template not working as expected
问题 In my Plunker here (modified Tour of Heroes app from official docs) I created this method in the hero.service doHeroesExist(): boolean { console.log("doHeroesExist called..", this.heroesExist); alert("doHeroesExist called.." + JSON.stringify(this.heroesExist)); return this.heroesExist; } and use it in the app.component class ngOnInit(): void { //this.getHeroes(); this.heroesExist = this.heroService.doHeroesExist; console.log("app ngOnInit called...", this.heroesExist); } as call the