1
我有以下文件:角2的雙向綁定不工作的電子應用的初始加載
topnav.component.ts
import { Component } from '@angular/core';
import { EnvironmentService } from '../services/ipc/environment.service';
const { ipcRenderer } = electron;
@Component({
selector: 'app-topnav',
templateUrl: './topnav.component.html',
styleUrls: ['./topnav.component.scss']
})
export class TopnavComponent {
version: string = null;
constructor(private environmentService: EnvironmentService) {
this.environmentService.getVersionInfo();
ipcRenderer.on('environment-reply', (event, arg) => {
console.log(arg);
this.version = arg;
});
}
}
topnav.component.html
...
<div *ngIf="version">{{version}}</div>
...
在代碼中,我正在檢索有關正在運行的環境的版本控制信息,並更新版本屬性並希望它在我的視圖中更新。調用getVersionInfo()是異步的,並使用ipcMain和ipcRenderer通信構造。我能夠驗證這些是否按預期工作。從角度和電子都沒有錯誤。
我已經驗證該版本確實回到arg參數中,並按預期記錄到控制檯;但是,直到我瀏覽我的應用程序之前,它並未顯示在視圖中。這導致我相信它與組件生命週期和Angular 2中的變化檢測有關。但是,我對Angular 2和Electron都有一些新手。
任何指示或想法可能會發生什麼以及如何解決它?
非常感謝!這工作完美。 –
這個解決方法做的工作,但我們被迫每次都調用這個run()方法...我試過這裏描述的解決方案沒有成功:http://stackoverflow.com/questions/41906986/two-way-data-binding -angular-2-in-electron-not-working ...很高興知道究竟是什麼讓Angular「不知道」受影響的區域如JavaScript庫的初始化順序... –
我認爲這將有助於https:// blog.thoughtram.io/angular/2016/02/01/zones-in-angular-2.html –