- 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.
推薦閱讀
- iOS面試一戰到底
- 編程卓越之道(卷3):軟件工程化
- INSTANT Weka How-to
- Practical Windows Forensics
- MariaDB High Performance
- Mastering Kali Linux for Web Penetration Testing
- Mastering AndEngine Game Development
- RabbitMQ Cookbook
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- jQuery炫酷應用實例集錦
- Application Development with Parse using iOS SDK
- 軟件測試技術
- Java程序設計及應用開發
- 系統分析師UML用例實戰
- Python人工智能項目實戰