我有 formcontrol,当我提供 [disable]="xyz"其中 xyz 是从 http 响应分配的组件中的变量时,angular2 给出以下警告。
看起来您正在将 disabled 属性与响应式(Reactive)表单指令一起使用。如果你设置 disabled 为 true 当您在组件类中设置此控件时,禁用属性实际上将在 DOM 中设置为 你。我们建议使用这种方法来避免“检查后更改”错误。
Example:
form = new FormGroup({
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
last: new FormControl('Drew', Validators.required)
});
所以我尝试禁用使用以下但不起作用
this.form = this.fb.group({'type': [{ value: '', disabled: this.xyz },[Validators.required]]});
最佳答案
你可以这样做:
yourHttpFunction(){
if(controlShouldBeDisabled){
this.form.controls['first'].disable()
}
}
关于Angular2 在 http 响应上启用/禁用 formcontrol 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40080951/