我是 Angular 4 的新手,对于比我更有经验的人,我可能有一些基本问题。
我有一个输入字段,当对象 user 存在时需要填充它的值。 所以基本上我需要 Angular 4 中的 php 函数 isset()。
我这样试过,但是不行。
<input class="form-control" type="text" value="{{ !!user.firstname ? user.firstname : null }}" id="firstname">
如有任何帮助,我们将不胜感激。
谢谢
最佳答案
您应该将 [(ngModel)] 与输入一起使用并使用 elvis 运算符来检查用户是否存在或使用 *ngIf
<input class="form-control" type="text" [(ngModel)]=user?.firstName id="firstname">
关于javascript - 如何在 Angular 4 中使用 NgIf 设置输入字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46847111/