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');
}
解决方案
方法是:-
editStudent(student)
{
this.router.navigate(['/addStudent', {'data' : JSON.stringify(student)}]);
}
ngOnInit() {
this.studentModel = JSON.parse(this.route.snapshot.paramMap.get('data'));
}
推荐阅读
- javascript - 有条件地跳过赛普拉斯中的测试
- css - 将修饰符样式应用于块或元素的最佳实践
- javascript - 迭代对象以创建带有选项组的选择
- json - JSON API 的渗透测试
- java - 当 Hibernate 实体具有 GenerationType.SEQUENCE 时,如何使用默认值序列将测试数据插入 H2
- c - 格式参数过多(printf 函数)
- mysql - SELECT COUNT 对具有 > 100M 行的表进行优化
- kubernetes - 我如何删除 DockerFile 并仅将 ci 文件与 kubernetes runner 一起使用
- c - getchar/putchar 在打印输入的字符时返回带有问号的框
- node.js - 带有额外文本输入字段的节点 js Multer 文件上传