【问题标题】:How to enable/disable Autocomplete component of Angular Material based on Angular2?如何启用/禁用基于 Angular2 的 Angular Material 的自动完成组件?
【发布时间】:2018-04-15 22:15:33
【问题描述】:

我无法动态或以其他方式启用/禁用autocomplete textfield component

我希望默认情况下禁用该组件。稍后在一些用户活动中,例如单击按钮,这应该启用组件。

我尝试了以下代码,但没有成功:

export class MyComponent {
  // this DIDN'T WORK
  opts:object={value: "", disabled: true};
  ctrl= new FormControl(this.opts);

  ngDoCheck(){  
    // this DIDN'T WORK
    // this could be ngOnChange, ngOnInit or button click event
    if(this.IsTextBoxEnabled){
      this.ctrl.enable();
    }else{
      this.ctrl.disable();
    }
  }
}

如何在 Angular Material Autocomplete 组件中做到这一点?

更新:
Similar issue on SO 也没有得到答复。我对此作出了回应。

【问题讨论】:

  • 你的尝试都应该有效,请提供一个 plunker,或者至少向我们展示你的模板 :)
  • 你能展示你的 HTML 吗?没有它,没有人可以帮助你。

标签: angular angular-material2


【解决方案1】:

我通过这样做得到了这个工作。

<input [attr.disabled]="IsTextBoxDisabled?'true':null">

显然我发现了这个here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 2018-10-19
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多