Object/array passing in the RouteParams via Routing angular2

前端 未结 1 564
轮回少年
轮回少年 2021-01-13 15:43

Working on Routing in angular2. actually i know we can send key/value using RouteParams in the routing but i want to send whole object/array in the RouteParams, i don\'t k

1条回答
  •  旧巷少年郎
    2021-01-13 15:52

    You can pass Objects to Url's in Angular2, but it's not really supported. The get-Method on routeParams only returns a string-representation, so you would get a string like "[Object]". If you want to access the passed data, you need to use the params-Property:

    constructor(@Inject(RouteParams) params:RouteParams, @Inject(Http) http:Http){
        this.data= params.params.data;
    }
    

    But beware, this only works properly the first time you call the route. If you call the route anothertime with different data, it can happen that params.params.data returns your old data although you put new data into the route.

    0 讨论(0)
提交回复
热议问题