Angular Passing Data Between Routes

后端 未结 3 574
傲寒
傲寒 2020-12-13 02:24

I have a little problem using routes in angular 4. You know, when I am trying to pass data from a component to another using navigate(\'root\', data), I just re

3条回答
  •  有刺的猬
    2020-12-13 02:50

    When you pass an object as a route parameter, it causes to call toString on that object and you get the result [object Object] from the object.

    const obj = {};
    console.log(obj.toString());

    If you want to pass complex type, you need to stringify it to a string and pass as a string. After when you get it, you need again to parse into an object.

    this.route.navigate(['/requests/fill', JSON.stringify(data)]);
    

    and access later

    const key: Products = JSON.parse(this.dataRoute.snapshot.params['objectProducts']);
    

提交回复
热议问题