2017-07-30 114 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>