2017-02-23 11 views
1

私はngclassに2つの条件を入れようとしていますが、誰も助けてくれる人はいません。角度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; 
} 

ここで私のアクティブなのはボーダーエラーのクラスで、私はクリック時にエラーを表示しようとしています。

+1

「アクティブ」から「アクティブ」に変更 –

+0

[ngClass] = "{active:submitted &&!form.co ntrols ['password']。valid} "。私は有効な..... – Daniel

+0

を忘れてしまったので、引用符なしで動作しますか? –

答えて

1

こんにちは、これを試すことができます!

私のためにうまく動作します!あなたは、フォームコントロールを使用している場合、入力タグ内に必要decleareする必要がいけない

ng-class=" {'active' : your condition, 'disabled' : your condition } " 
0

、あなたは、TS内でそれをdecleareする必要が

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']; 
} 
関連する問題