首页 > 解决方案 > 读取路由参数中的对象参数

问题描述

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

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'); 
  }

标签: angular

解决方案


方法是:-

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

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

推荐阅读