angular - 角度数据未显示在模板中
问题描述
我有带角度的 Ionic 应用程序,我得到了我的数据,constructor
但无法打印它们html
代码
component
receiver: any;
constructor(
//....
) {
// get receiver data
const receiverData = this.activatedRoute.snapshot.paramMap.get('receiverData');
console.log('receiver data: ', receiverData); // does print the data (sample data below)
this.receiver = receiverData;
}
HTML
<ion-title [innerHTML]="receiver?.username"></ion-title>
Sample data (returned by "console.log('receiver data: ', receiverData);"
receiver data: {
"id":4,
"name":"Tester",
"username":"Utester",
"phone":"081000000000",
"photo":null,
"email":"tester@admin.com",
"created_at":"2020-06-21T09:06:15.000000Z"
}
知道为什么我的数据没有以 html 格式打印吗?
解决方案
通常,如果它是对象,它可以正常工作而没有问题。但是您可以将字符串作为类型发送然后尝试解析它
this.receiver = JSON.parse(receiverData);
推荐阅读
- java - ojdbc resultSet.next() 触发下一行的网络通信
- mongodb - MongoDB 可以使用通配符索引进行交集吗?
- electron - (节点:15864)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“匹配”
- iphone - iphone连接到ubuntu
- html - 使用 alpha 继承父背景颜色会使子背景颜色不同。为什么?
- html - 自己的 wordpress 主题中的图像未显示
- elasticsearch - 如何在重新索引时传递多个管道
- docker-compose - 如何编写预部署脚本以在 .gitlab-ci.yml 文件中运行 newman postman 测试
- php - 自动完成文本未显示实际数据代码点火器?
- php - MSSQL int 递增 1:递增 2 而不是 1