在userdata
我有firstname
,lastname
....所以我想在homecomponent.html中绑定firstname
,那么如何在html中绑定它模板?
export class HomeComponent {
constructor(private authenticationService : AuthenticationService) {
userdata=this.authenticationService.user_data;
}
}
答案 0 :(得分:1)
只是,
<div><h1>{{userdata.firstname}}</h1></div>
修改强>
如果您的数据来自异步调用,则使用elvis运算符检查值是否存在,
<div><h1>{{userdata?.firstname}}</h1></div>
答案 1 :(得分:0)
如果您正在讨论插值,您可以在html中显示<p>{{userdata.firstname}} {{userdata.lastname}}</p>
对象的任何字段:
.container{
position: relative;
}