如何在侦听器中正确调用此函数('this'对窗口范围的引用)?
this.openPackage = function (package) {
...
}
$rootScope.$on('open_Package', function (event, package) {
openPackage(package); // doesn't work
});
答案 0 :(得分:0)
只需使用箭头功能即可保持上下文:
$rootScope.$on('open_Package', (event, package) => {
this.openPackage(package); // does work
});