angular4 在页面跳转的时候传递多个参数到新页面

页面跳转

router.navigate
//单一参数:
this.router.navigate(['/detail',id]); //多个参数:
this.router.navigate(['/detail'],{queryParams:{'name':'nihao'}}); router.navigateByUrl //单一参数:
this.router.navigateByUrl('/detail/id'); //多个参数:
this.router.navigateByUrl('/detail',{queryParams:{'name':'nihao'}});

在新页面接收参数

//1.snapshot

import { ActivateRoute } from '@angular/router';
public data: any;
constructor( public route: ActivateRoute ) { };
ngOnInit(){
this.data = this.route.snapshot.params['id'];
}; //2.queryParams import { ActivateRoute } from '@angular/router';
public data: any;
constructor( public activeRoute:ActivateRoute ) { };
ngOnInit(){
this.activeRoute.queryParams.subscribe(params => {
this.data = params['name'];
});
};
上一篇:删除64位ODBC数据源DNS


下一篇:node.js事件触发