700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > AngularJs中 URL地址参数改变 视图不更新的解决办法(监听URL变化 重新加载数据方法)

AngularJs中 URL地址参数改变 视图不更新的解决办法(监听URL变化 重新加载数据方法)

时间:2022-12-02 22:26:54

相关推荐

AngularJs中 URL地址参数改变 视图不更新的解决办法(监听URL变化 重新加载数据方法)

引入

import {ActivatedRoute,Router,NavigationEnd } from '@angular/router';//实例化Routerconstructor(private router:Router) {}

需要导入rxjs这个库才能使用filter方法

import {filter } from 'rxjs/operators';

ngAfterViewInit(){// 监听路由变化this.router.events.pipe(filter((event:any) => event instanceof NavigationEnd)).subscribe((event:NavigationEnd) => {// 加载数据方法(下面这里写自己的代码)console.log(event)this.type=this.route.snapshot.params.typethis.qingkong();//可以用封装好的函数,地址发生变化,重新加载页面数据});}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。