javascript - How to set value of input field with NgIf in Angular 4 - Stack Overflow

I am pretty new with Angular 4 and I have probably basic question for someone who is a bit more experie

I am pretty new with Angular 4 and I have probably basic question for someone who is a bit more experienced than me.

I have input field which value needs to be populated when object user exists. So basically I need php function isset() in angular 4.

I tried like this but it is not working.

<input class="form-control" type="text"  value="{{ !!user.firstname ? user.firstname : null }}" id="firstname">

Any help would be appreciated.

Tnx

I am pretty new with Angular 4 and I have probably basic question for someone who is a bit more experienced than me.

I have input field which value needs to be populated when object user exists. So basically I need php function isset() in angular 4.

I tried like this but it is not working.

<input class="form-control" type="text"  value="{{ !!user.firstname ? user.firstname : null }}" id="firstname">

Any help would be appreciated.

Tnx

Share Improve this question asked Oct 20, 2017 at 10:22 dj.milojevicdj.milojevic 2141 gold badge5 silver badges12 bronze badges 1
  • 1 use [(ngModel)] instead of value – Shubham Agrawal Commented Oct 20, 2017 at 10:26
Add a ment  | 

2 Answers 2

Reset to default 3

You should use [(ngModel)] with input and use elvis operator to check if the user exists or use *ngIf

<input class="form-control" type="text"  [(ngModel)]=user?.firstName id="firstname">

Try this :

<input class="form-control" type="text" [value]="user.firstname ? user.firstname : null"  name="firstname" id="firstname">

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745107070a4611622.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信