3
なぜangle2双方向データバインディングがこのシナリオで機能しないのですか?Angular2 ngModelが非同期コールバック後に更新されない
<span style="color:white">{{searchLocation}}</span>
<input name="searchLocation" type="text" placeholder="Search" [(ngModel)]="searchLocation">
<button class="btn btn-outline-success" type="submit" (click)="search()">Search</button>
目標成分が後HeaderComponent
export class HeaderComponent implements OnInit {
searchLocation: string;
@Output() locationFound: EventEmitter<Position> = new EventEmitter<Position>();
constructor(private _locationService: LocationService) { }
ngOnInit() {
this.searchLocation ="";
}
search():void{
this._locationService.geocodeAddress(this.searchLocation)
.subscribe((position:Position)=>{
this.searchLocation ="new value";
this.locationFound.emit(position);
});
}
}
あるsearchLocation変化をブロック購読が、ビューが更新されません。
私は誰かがsearchLocationがヌルに割り当てられている
「searchLocation」が更新されるはずの部分が何とか見逃されています。私は 'this.searchLocation =" ";' 2回だけは変更の大部分ではありません;-)参照してください。 –