2017-06-14 91 views
1

这是另一个“View not changing”问题Angular2:View not updating

我有一个组件,当我选择一个名称时需要更新。 但是,我不知道为什么,我必须在模型更改之前选择名称的2倍。这就像我第一次选择模型没有更新。

采用了棱角分明2 4.0.0与materializeCSS(自动完成从Materialise公司推出)

Example

那么,我想直接拥有该按钮出现一次我选择。

这部分的HTML模板:

<form> 
      <i class="material-icons prefix">search</i> 
      <input id="search" type="text" name="autoComplete" materialize="autocomplete" [materializeParams]="[autocompleteInit]"> 
     </form> 
     <div *ngIf="CVSelected.getCV()"> 
      <button type="button" [routerLink]="['/dashboard/cv']" class="waves-effect waves-light btn">Passer à l'édition</button> 
     </div> 

AutocompleteInit:

autocompleteInit: any = { 
    data: {Some_data_here}, 
    onAutocomplete: (str: string) => { 
     this.dataService.GetFromString(str).subscribe(value => { 
      console.log(value); 
      this.CVSelected.setCV(value[0]); // This makes the button appears on my template with a get 
     }); 
     this.changement.detectChanges(); // Tried this and other functions that does the same but doesn't work 
    }, 
}; 

任何人都遇到了这个问题?如果是,有些解决方案?

预先感谢您

+0

检查'的console.log(Zone.current.name)''里面处理onAutocomplete' – yurzui

+0

找不到有关区图书馆。 current.name。我在哪里找到它? –

+0

它的zonejs。 '声明让Zone:任何' – yurzui

回答

2

在这种情况下最可能的原因是角度区外的执行代码。为了解决这个问题,我会建议你到角区域中运行的代码,如:

constructor(private zone: NgZone) { } 

autocompleteInit: any = { 
    data: {}, 
    onAutocomplete: (str: string) => { 
    zone.run(() => { 
     this.dataService.GetFromString(str).subscribe(value => { 
      console.log(value); 
      this.CVSelected.setCV(value[0]); // This makes the button appears on my template with a get 
     }); 
    }); 
    },