Home > Article > Web Front-end > Angular2 page size changes
1. Phenomenon
Charts in full-screen pages often need to be resized to adapt to page size changes. This article mainly introduces the solution for Angular2 to monitor page size changes. Friends who need it You can refer to it, I hope it can help everyone.
2. Solution
1. Introduction:
import { Observable } from 'rxjs';
2. Use (in ngOnInit method):
ngOnInit() { // 页面监听 Observable.fromEvent(window, 'resize') .debounceTime(100) // 以免频繁处理 .subscribe((event) => { // 这里处理页面变化时的操作 console.log('come on ..'); }); }
3. Summary
Research whether there are more ways to log out these monitors when switching? To avoid memory leaks. Whenever possible, in the ngOnDestroy() method.
Related recommendations:
A simple way to build an angular2.0 project
Detailed examples of how Angular2 integrates other plug-ins
The above is the detailed content of Angular2 page size changes. For more information, please follow other related articles on the PHP Chinese website!