我正在研究一个函数,有人可以给出关于如何指定一个函数外面的函数的建议吗? 在if语句中我想调用otherfunction()。Angular 2:Ts:嵌套函数
@Injectable()
export class menuService {
constructor(){}
testing(){ console.log('something')}
loadwidget(){
// not able to call this function
this.testing()
}
}
错误,我得到的是“this.testing是不是一个函数”
ERROR TypeError: this.testing is not a function
at Object.menuService.loadwidget (http://localhost:3000/main.bundle.js:755:14)
at Object.eval [as handleEvent] (ng:///AppModule/tbuttonsComponent.ngfactory.js:36:41)
at handleEvent (http://localhost:3000/vendor.dll.js:13146:138)
at callWithDebugContext (http://localhost:3000/vendor.dll.js:14354:42)
at Object.debugHandleEvent [as handleEvent] (http://localhost:3000/vendor.dll.js:13942:12)
at dispatchEvent (http://localhost:3000/vendor.dll.js:10121:21)
at http://localhost:3000/vendor.dll.js:10711:38
https://plnkr.co/edit/XCHsu19UhR9wWxz4VLOx?p=preview
难道因为它是注射剂吗? –
@ChrisTarasovs看看我的编辑,这不是一个@injectable问题,这是'this'没有绑定到'menuService'的问题。 – IAmKale