【发布时间】:2018-03-06 16:32:47
【问题描述】:
setting.component.ts
import { Component, OnInit } from '@angular/core';
import { ElectronService } from 'ngx-electron';
@Component({
selector: 'app-setting',
templateUrl: './setting.component.html',
styleUrls: ['./setting.component.css']
})
export class SettingComponent implements OnInit {
private primaryServer: string;
private secondaryServer: string;
constructor(
private electron: ElectronService
) { }
ngOnInit() {
this.electron.ipcRenderer.send("asynchronous-message", {get: "settings"})
this.electron.ipcRenderer.on("asynchronous-reply", (event, data) => {
this.primaryServer = data.database.primary;
this.secondaryServer = data.database.secondary;
})
}
}
setting.component.html
<p>{{primaryServer}}</p>
<p>{{secondaryServer}}</p>
当页面加载时,我的“primaryServer”和“secondaryServer”值不显示。但是,当我单击输入或随机按钮时,它会显示出来。如何让它们出现在 init 上?
【问题讨论】:
-
您的代码可能在 Angulars 区域之外运行,因此 Angular 无法识别它需要运行更改检测。您可以使用
zone.run(() => { your code that updates the model here })将代码强制返回到该区域。如果这可行,您可以进一步调查为什么它在 Angulars 区域之外运行。 -
您确定收到了数据吗?是同步的还是异步的?
-
@GünterZöchbauer 成功了。谢谢。