我是Typescript的新手。我想在doSomething
的末尾调用类Maincontroller
的方法initialiseMap
。如果我使用this
我会收到错误,当我使用MainController.prototype.doSomething($scope,'Test')
调用它时,似乎没有任何事情发生。
class MainController {
constructor($http, $scope, $timeout, socket) {
// some code
this.initialiseMap($scope, $timeout);
}
initialiseMap($scope, $timeout){
// some more code
// I need to call doSomething($scope,'Test') from here
}
doSomething ($scope, smth) {
// even more code
}
}
答案 0 :(得分:0)
在我的电脑上运行得非常好。当然,请尝试以下代码:
class MainController {
constructor($http, $scope, $timeout, socket) {
// some code
this.initialiseMap($scope, $timeout);
}
initialiseMap($scope, $timeout){
// some more code
// I need to call doSomething($scope,'Test') from here
console.log($scope, $timeout);
}
doSomething ($scope, smth) {
// even more code
}
}
创建一个实例,会显示$scope
和$timeout
的值。