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

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.

主站蜘蛛池模板: 平南县| 剑河县| 汶上县| 梁平县| 赤水市| 贺兰县| 陇川县| 厦门市| 嘉义县| 常宁市| 图们市| 大庆市| 渝中区| 沅陵县| 闻喜县| 探索| 宜城市| 饶阳县| 蓬莱市| 得荣县| 礼泉县| 虹口区| 建昌县| 济阳县| 平南县| 玉溪市| 昌黎县| 阿坝| 榆树市| 长兴县| 高淳县| 肇源县| 陵水| 井陉县| 乌苏市| 宣化县| 曲水县| 海淀区| 宁强县| 沅陵县| 达拉特旗|