[英]How to put 2 conditions in ngClass in angular 2
我試圖在我的 ngclass 中加入 2 個條件,但它不起作用。
<input type="password" [ngClass]="{active: submitted && !form.controls['password']}" [formControl]="form.controls['password']" required>
this.submitted = false;
onSubmit(form: any) {
this.submitted = true;
}
我的活動是一個帶有邊框錯誤的類,我試圖在點擊時顯示錯誤。
嗨,你可以試試這個!
為我工作很好!
ng-class=" {'active' : your condition, 'disabled' : your condition } "
如果您使用表單控件,則不需要在輸入標簽內取消清除要求,您需要在 ts 文件內取消清除它
HTML
<input type="password" [ngClass]="{'active': isActive()}" [formControl]="form.controls['password']">
打字稿
constractor(fb : FormBuilder){
this.submitted = false;
this.form = fb.group({
password: new FormControl({value: null}, Validators.compose([Validators.required]))
});
}
onSubmit(form: any) {
this.submitted = true;
}
isActive(){
return this.submitted && !this.form.controls['password'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.