【发布时间】:2017-10-03 03:15:38
【问题描述】:
我正在使用 ipcRenderer 从我的 main.js 中的浏览器对话框中检索文件夹路径。
但由于某种原因,它不会更新我视图中的文本字符串。
我知道为了让它工作,我需要做一个 setTimeout 来更新它(感谢谷歌!)。但由于某种原因,这不起作用。
我使用的代码如下。
import { Component, OnInit } from '@angular/core';
declare var electron: any;
@Component({
selector: 'my-app',
template:
//added (click)="debug()" in order to update the {{path}} manually
`<h1 (click)="debug()">My First Angular 2 App with Electron</h1>
<br />Project Path: {{[(path)]}}
<button (click)="btnClick()">Select project path</button>
<br /> <br />`
})
export class AppComponent implements OnInit {
ipc:any;
path:string;
constructor(){
this.path = __dirname;
}
ngOnInit(){
electron.ipcRenderer.on('project-path-reply', (event, arg) => {
setTimeout(() => {
this.path = arg.return[0];
console.log('updated')
})
})
}
btnClick(){
electron.ipcRenderer.send('project-path',1);
}
debug(){
console.log(this.path);
}
}
谁能指出我正确的方向这是我第一个使用电子的应用程序。
亲切的问候,
Tyvo
【问题讨论】:
-
你试过
contructor(private ref ChangeDetectorRef){}然后在回调ref.detectChanges()?
标签: angular ipc settimeout electron