您的位置:首页 > Web前端 > AngularJS

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

2019-04-18 11:12 1006 查看

引入

import { ActivatedRoute,Router,NavigationEnd } from '@angular/router';
//实例化Router
constructor(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.type
this.qingkong();//可以用封装好的函数,地址发生变化,重新加载页面数据
});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐