官术网_书友最值得收藏!

Detecting application state changes

To detect a state change, we can, luckily, use the Angular router's change event and take actions based on that. So, import the Router module in your app.component.ts  and then use that to detect any state change:

import { Router, NavigationEnd } from '@angular/router';
import { Stack } from './utils/stack';

...
...

constructor
(private stack: Stack, private router: Router) {

// subscribe to the routers event
this.router.events.subscribe((val) => {

// determine of router is telling us that it has ended
transition
if(val instanceof NavigationEnd) {

// state change done, add to stack
this.stack.push(val);
}
});
}

Any action that the user takes that results in a state change is now being saved into our stack, and we can move on to designing our layout and the back button that transitions the states.

主站蜘蛛池模板: 汉中市| 长汀县| 浠水县| 定南县| 珲春市| 镇安县| 克什克腾旗| 岳西县| 兰考县| 托克逊县| 新巴尔虎左旗| 延安市| 克拉玛依市| 仙游县| 黄冈市| 育儿| 海淀区| 广安市| 寻乌县| 通江县| 边坝县| 崇信县| 溆浦县| 方山县| 胶南市| 敦煌市| 东城区| 大连市| 康马县| 鹿泉市| 杨浦区| 安远县| 宝山区| 安陆市| 易门县| 南雄市| 南漳县| 大邑县| 山东省| 阳城县| 通渭县|