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'];
    });
};

 

posted @ 2018-04-11 17:48  c-137Summer  阅读(1010)  评论(0编辑  收藏  举报