Angular 4如何触发更改,如jquery触发器('更改')

时间:2017-11-22 07:29:27

标签: angular trigger.io

我试图在this.my_var = my_val中输入值之后触发输入字段的角度4更改,然后如何触发更改事件?

代码 -



import { Component, OnInit,OnDestroy, Renderer, ElementRef, ViewChild } from '@angular/core';
 @ViewChild('mka_gb') mka_gb:ElementRef;
 
 constructor(private router: Router, private renderer:Renderer) {  }

  ngOnInit() {
    this.getOverviewData(); 
    let search = window.localStorage.getItem('search_val');
    window.localStorage.setItem('search_val', '');
    console.log(search);
    if(search != '') {
      setTimeout(()=>{
        this.mka_search = search;
        let event = new MouseEvent('click', {bubbles: true});
        this.renderer.invokeElementMethod(
        this.mka_gb.nativeElement, 'dispatchEvent', [event]);
      },300);
      
    }
  }

<input #mka_gb type="text" pInputText size="50" placeholder="Global Filter" class="form-control" [ngModel]="mka_search">
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您可以使用ViewChild:

import { Component, Renderer, ElementRef, ViewChild } from '@angular/core';
@Component({
  ...
  template: `
...
<input #fileInput type="file" id="imgFile" (click)="onChange($event)" >
...`
})
class MyComponent {
  @ViewChild('fileInput') fileInput:ElementRef;

  constructor(private renderer:Renderer) {}

  exampleFunctionWhenYouWantToFireEvent() {
    let event = new MouseEvent('click', {bubbles: true});
    this.renderer.invokeElementMethod(
        this.fileInput.nativeElement, 'dispatchEvent', [event]);
  }
}

答案 1 :(得分:0)

我找到了问题的解决方案:

&#13;
&#13;
def conv(x):
    return np.nan if x.strip() == '-"-' else x.strip()

#define each column
convs={'index1': conv, 'current_tm': conv, 'country_state':conv}
df = pd.read_csv(StringIO(myst), converters=convs, names = u_cols)
print (df)
     country_state    index1 current_tm
0  india / gujarat  22905034      19:44
1   india / kerala       NaN      19:33
2              NaN    905154      21:56
&#13;
&#13;
&#13;