- Hands-On Data Structures and Algorithms with JavaScript
- Kashyap Mukkamala
- 142字
- 2021-06-30 19:12:09
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.
推薦閱讀
- 解構(gòu)產(chǎn)品經(jīng)理:互聯(lián)網(wǎng)產(chǎn)品策劃入門寶典
- Animate CC二維動畫設(shè)計與制作(微課版)
- Python GUI Programming Cookbook
- Getting Started with Python Data Analysis
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- Java:High-Performance Apps with Java 9
- Teaching with Google Classroom
- Haskell Data Analysis Cookbook
- Creating Stunning Dashboards with QlikView
- Python Interviews
- Spring技術(shù)內(nèi)幕:深入解析Spring架構(gòu)與設(shè)計原理(第2版)
- Illustrator CS6設(shè)計與應(yīng)用任務(wù)教程
- uni-app跨平臺開發(fā)與應(yīng)用從入門到實踐
- Mastering Apache Camel
- Clojure High Performance Programming(Second Edition)