I am developing an angular2 application that is similar to the Plunkr link provided at the end.
In HeroService, I have a clickCount property that will increase when the hero clicks. But after logging in, I want to reset this parameter. I do not want to use the service and reset its value (in fact, in my application I use many services, so I can not use every service and reset its value when I exit the system).
Is there any method to reset / reload a service for a specific action without reloading the entire application. Hero Service Below
import { Hero } from './hero'; import { HEROES } from './mock-heroes'; import { Injectable } from '@angular/core'; @Injectable() export class HeroService { getHeroes(): Promise<Hero[]> { return Promise.resolve(HEROES); } getHeroesSlowly(): Promise<Hero[]> { return new Promise<Hero[]>(resolve => setTimeout(resolve, 2000)) // delay 2 seconds .then(() => this.getHeroes()); } getHero(id: number): Promise<Hero> { return this.getHeroes() .then(heroes => heroes.find(hero => hero.id === id)); } }
Plunkr link
source share