【问题标题】:Set formNameGroup value inside directive在指令内设置 formNameGroup 值
【发布时间】:2017-03-03 02:39:34
【问题描述】:

我正在使用响应式表单。在我的指令中,我可以通过 `ElementRef.

访问元素

但是,当我尝试使用 this.element.nativeElement.value = 'new text' 设置我的 textarea 元素的值时,该值不会更新,并且 formGroupName 不会触发任何 changeValues

如何正确设置使用 formGroupName 的 textarea 元素的值?

【问题讨论】:

    标签: angular angular2-directives


    【解决方案1】:

    以这种方式更改值时,您仍然需要调度事件。它不会自动发送。这就是指令知道值已更改的方式;通过监听输入事件。

    this.element.nativeElement.value = 'new text'
    this.element.nativeElement.dispatchEvent(new Event('input'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      相关资源
      最近更新 更多