在路由参数中读取对象参数

时间:2019-09-01 11:21:26

标签: angular

我正在尝试发送对象参数。来自列表组件。

editStudent(student)
   {
    this.router.navigate(['/addStudent', student]); 
   }

studentModel对象类似于:

addressModel = new AddressClass("", "", "");
  studentModel = new StudentClass(0,"", "", "", "", "", true, "", this.addressModel)

我正在尝试在其他组件上读取学生对象:

ngOnInit() {      
    this.studentModel = this.route.snapshot.paramMap.get('stud'); 
  }

1 个答案:

答案 0 :(得分:0)

方法是:-

editStudent(student)
{
 this.router.navigate(['/addStudent', {'data' : JSON.stringify(student)}]); 
}

ngOnInit() {      
this.studentModel = JSON.parse(this.route.snapshot.paramMap.get('data')); 
}