路由多引數傳參及接收
阿新 • • 發佈:2018-12-23
1.導航需要跳轉的地址,兵役json物件格式傳入多個引數,key值可以隨便籤,但後面的頁面接收引數獲取的值一定要和這個key值對應才可以
import { Router } from '@angular/router';//需要引入的庫類。 constructor( //在構造器中宣告 private router:Router, ) { } /** * 導航到應用詳情 */ goApplicationDetail(instanceId:number,ownerShip:boolean){ return this.router.navigate(['/console/details/appDetail',{"instanceId":instanceId,"ownerShip":ownerShip}]); }
2.接受的路由地址中不需要定義接收任何引數
{ path: "appDetail", component: DetailsComponent}
3.跳轉後的組建中,在構造其中獲取引數
import {ActivatedRoute } from '@angular/router';//需要引入的庫類 constructor( private route:ActivatedRoute ) { this.appId = this.route.params["value"].instanceId; this.tempOwnerShip = this.route.params["value"].ownerShip; this.tempOwnerShip==="true"?this.ownerShip =true:this.ownerShip =false; console.log("appid="+this.appId); console.log("ownerShip="+this.ownerShip); }