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

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.

主站蜘蛛池模板: 平南县| 九台市| 麻栗坡县| 泗洪县| 潢川县| 财经| 旌德县| 泾源县| 叙永县| 彰武县| 莱芜市| 芜湖市| 柘荣县| 斗六市| 明溪县| 清流县| 阿拉善右旗| 泰来县| 右玉县| 南投市| 德保县| 射阳县| 北宁市| 庆阳市| 台州市| 卫辉市| 清徐县| 大理市| 张家界市| 庆元县| 富阳市| 确山县| 山阴县| 大埔县| 天气| 太和县| 剑河县| 铜川市| 博野县| 禹州市| 临安市|