zoukankan      html  css  js  c++  java
  • 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'];
        });
    };
  • 相关阅读:
    scrollTop
    ……
    放下
    值得纪念的一天
    php新手上路(六)
    image map
    文字多出用点代替
    js formatter
    感谢,今天刚申请了博客园,
    接口的作用
  • 原文地址:https://www.cnblogs.com/leiting/p/8797302.html
Copyright © 2011-2022 走看看