【发布时间】:2020-02-29 09:20:55
【问题描述】:
简化我得到了一个视图:
<table class="table table-bordered table-striped">
<tr>
<td>
<label>First Name</label>
<input type="text" class="form-control" [(ngModel)]="profile.FirstName">
</td>
<td>
<label>Last Name</label>
<input type="text" class="form-control" [(ngModel)]="profile.LastName">
</td>
</tr>
</table>
构造函数创建空白配置文件并且 ngOnInit 检查更改的组件:
profile: Profile;
sub: any;
constructor(private serv: ProfileService, private route: ActivatedRoute) {
this.profile = new Profile('', '');
}
ngOnInit(): void {
this.sub = this.route.params.subscribe(params => {
const id = params['id'];
this.serv.getProfile(id).subscribe(res => {
console.log(res);
this.profile = res;
// this.profile.LastName = res.LastName; doesn't work either
});
});
}
在控制台上记录了正确的配置文件,但表格字段未更新。怎么了? 感谢您的帮助!
【问题讨论】:
标签: angular