从AngularJS中的$scope定义的另一个函数调用在$scope上定义的函数

时间:2021-10-10 23:57:05

I have a controller with many functions defined on $scope.

我有一个在$scope上定义了许多函数的控制器。

Ex:

例:

$scope.doSomething = function() {

}

$scope.doSomethingElse = function(data) {

}

From my doSomething function, I want to call my doSomethingElse function. Right now, I am calling it in the success function of my HTTP request (yes, it is succeeding).

从doSomething函数中,我想调用doSomething else函数。现在,我在HTTP请求的success函数中调用它(是的,它正在成功)。

Once the success function triggers, I'm calling the other function like so:

一旦成功函数触发,我就像这样调用另一个函数:

angular.scope().doSomethingElse(data); The data variable is passed through as a parameter in the success function.

angular.scope().doSomethingElse(数据);数据变量作为一个参数在success函数中传递。

After running, I'm receiving this error: TypeError: undefined is not a function

在运行之后,我收到了这个错误:TypeError: undefined不是函数

Is there another way to do this?

还有别的办法吗?

1 个解决方案

#1


3  

You can just call $scope.doSomethingElse(data); since you've already defined it as a function. As long as it is defined before you call it, this will work.

只需调用$scope。dosomething else(数据);因为你已经把它定义为一个函数。只要在调用之前定义它,它就可以工作。

#1


3  

You can just call $scope.doSomethingElse(data); since you've already defined it as a function. As long as it is defined before you call it, this will work.

只需调用$scope。dosomething else(数据);因为你已经把它定义为一个函数。只要在调用之前定义它,它就可以工作。