我挑战了在组件上显示当前选定值的问题。其中的NgModel是可观察的,在运行时发生了变化。
<select [ngModel]="selectedVersion$ | async" (ngModelChange)="changeVersion($event)" class="dropdown">
<option *ngFor="let version of versions" [ngValue]="version">{{version.fullName}}</option>
</select>
selectedVersion $是Observable类型的ngRedux值:
selectedLanguage$: Observable<string>;
constructor(
private ngRedux: NgRedux<IAppState>,
private actions: TopbarActions,
private cookieService: CookieService) {
this.selectedVersion$ = ngRedux.select<Version>('version');
}
ngOnInit(): void {
this.subscription.add(this.selectedVersion$.subscribe(version => {
this.checkExistence(version, this.versionSelectionCallback, this);
}));
当我发送新版本时 - selectedVersion $变量已更新:
changeVersion(version: Version): void {
this.ngRedux.dispatch(this.actions.setVersion(version));
this.cookieService.set("rcm-version", JSON.stringify(version), 5, "/");
}
(我通过显示async和json管道在视图模板上更改了它):
{{selectedVersion$ | async | json}}
但组件上的选定值未更新。 我试图强制改变检测周期,但它也不起作用。
任何帮助将不胜感激!