json - 无法使用界面用户读取未定义角度 wite 的属性“知道”
问题描述
我正在使用角度服务从我的服务器获取数据,这是我的用户服务代码。
GetUser(id: any): Observable<User>
{
const header = new HttpHeaders();
header.append('content-type', 'application/json');
return this.httpclient.get<User>(this.baseurl + '/' + id, {headers: header});
}
模型用户
export interface User {
id: number;
username: string;
knowas: string;
age: number;
gender: string;
created: Date;
lastActive: Date;
photourl: string;
city: string;
country: string;
introduction?: string;
lookingFor?: string;
photos?: Photo[];
}
我使用我的 memberdetialcomponent.ts 中的代码和我的代码。
export class MemberDetialComponent implements OnInit {
user: User;
id: number;
constructor(private userservice: UserService, private alertify: AlertifyService, private route: ActivatedRoute) { }
ngOnInit() {
this.loaduser();
console.log(this.user);
}
// tslint:disable-next-line: typedef
loaduser()
{
this.userservice.GetUser(+this.route.snapshot.params['id']).subscribe(
(users: User) =>
{
this.user = users;
// console.log(this.user);
}, ( error) =>
{
this.alertify.error(error);
}
);
}
}
当使用 console.log(this.user); 我得到了信息,但在我的 html 中使用它说无法读取您的财产知道。这是我的 html 代码
<h6>
{{user.knowas}}
</h6>
有人可以帮我解决这个问题吗?谢谢
解决方案
推荐阅读
- java - 访问 WEB-INF 文件夹中的网站背景和其他装饰图像
- python - 子集总和包括动态方法的负数
- android - kotlin.UninitializedPropertyAccessException - lateinit 属性 mAdapter 尚未初始化 - Android 开发
- vue.js - GET http://localhost:3000/api/eventNames net::ERR_CONNECTION_REFUSED
- python-3.x - 根据 Pandas 中的前缀将多列融合到对应的列
- python - 在 tkinter 中将文本添加到自定义圆形按钮
- jenkins - 在没有 Artifactory 插件的情况下将 Jenkins 凭据传递给 Artifactory
- javascript - 是什么导致我的支付网关设置失败?
- asp.net - 将字符串与配置文件中的 Octopus 变量连接起来
- ios - 尝试将图像存储为 base64 并使用它