のdisabled属性を使用しようとしていますformControl。私がそれをテンプレートに入れると、うまくいきます:
<md-input formControlName="id" placeholder="ID" [disabled]="true"></md-input>
しかし、ブラウザは私に警告します:
無効属性を反応フォームディレクティブで使用しているようです。コンポーネントクラスでこのコントロールを設定するときにdisabledをtrueに設定すると、disabled属性が実際にDOMに設定されます。この方法を使用して、「チェック後に変更」エラーを回避することをお勧めします。
Example: form = new FormGroup({ first: new FormControl({value: 'Nancy', disabled: true}, Validators.required), last: new FormControl('Drew', Validators.required) });
だから私はそれを FormControl、テンプレートから削除しました:
constructor(private itemsService: ItemsService) {
this._items = [];
this.myForm = new FormGroup({
id: new FormControl({value: '', disabled: true}, Validators.required),
title: new FormControl(),
description: new FormControl()
});
this.id = this.myForm.controls['id'];
this.title = this.myForm.controls['title'];
this.description = this.myForm.controls['description'];
this.id.patchValue(this._items.length);
}
しかし、それは機能しません(を無効にしませんinput)。何が問題ですか?