2017-07-30 74 views
-2

什么是不正确的?我想显示这个属性,如果错误如何使它正确?Angular 2属性和* ngIf

<label for="email" *ngIf="(form.controls.email.errors && form.controls.email.dirty) ? true : [attr.data-error]="wrong" ">E-Mail</label> 
<input type="email" name="email" autocomplete="off" formControlName="email"> 

回答

0

你可以尝试这样的事情

<label for="email" 
*ngIf="form.controls.email.errors && form.controls.email.dirty" 
[attr.data-error]="form.controls.email.errors && form.controls.email.dirty? 
'wrong': ''" > 
E-Mail</label> 

1
<label for="email" [attr.data-error]="(form.controls.email.errors && form.controls.email.dirty)? 'wrong': null">E-Mail</label>