【发布时间】:2017-03-10 15:15:32
【问题描述】:
在 angular2 中,我有以下组件:
import { Component } from '@angular/core';
const dialog = require("electron").dialog;
const xml2js = require('xml2js');
const fs = require("fs");
const ipc = require('electron').ipcRenderer;
@Component({
selector: 'ct-config-editor',
templateUrl: 'config.editor.component.html'
})
export class ConfigEditorComponent {
constructor() {
this.selected_file = 'Max';
}
clicked(event){
alert("lol");
ipc.send('open-file-dialog');
ipc.on('selected-directory', function (event, path) {
this.selected_file = `You selected: ${path}`;
});
}
}
视图有一个正确绑定的属性,称为 selected_file,如下所示:
<h1>{{selected_file}}</h1>
H1 的值在开始时是最大值 -- 但是在我的回调运行后,我无法访问 this.selected_file,因为“this”的上下文不是我的类。
如何在回调中访问我的实例变量?
【问题讨论】:
标签: javascript angular electron