0
内結合インスタンス変数にアクセス:Angular2は、私は次のコンポーネントを持って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'のコンテキストが自分のクラスではないため、this.selected_file
にアクセスすることはできません。
コールバック内でインスタンス変数にアクセスするにはどうすればよいですか?
はこれですも参照してください。ベストプラクティス?私は特に矢印の機能が何をしているのか理解していません! – RenegadeAndy