我正在研究一個函數,有人可以給出關於如何指定一個函數外面的函數的建議嗎? 在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