【问题标题】:Reset specific input text value when method call方法调用时重置特定输入文本值
【发布时间】:2018-08-18 21:54:07
【问题描述】:

如何从另一个组件中清除文本框值。

app.component.html

 <input id="search"
         type="text"
         class="form-control"
         name="criteria"
         placeholder="Search000"
         [(ngModel)]="_criteria"
         (ngModelChange)="criteriaChange()"
          >

【问题讨论】:

标签: angular angular2-forms angular5


【解决方案1】:

试试这个,Angular 2 changing component variables on another component

这一切都取决于这些组件的关系以及是否可以直接获取该组件的句柄。前任。在测试用例中,我可以轻松更改任何组件的属性。

【讨论】:

    【解决方案2】:

    就我个人而言,我只会使用 JQuery 并在 angular click 事件中,我会清除值;但如果你想使用角度。

    实现这一点的一种方法是利用@ViewChild

    @ViewChild(NameOfComponent) nameOfComponent: NameOfComponent;
    
    this.nameOfComponent.whatEverYouWantToAccess.
    

    【讨论】:

      猜你喜欢
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 1970-01-01
      • 2020-07-28
      相关资源
      最近更新 更多