我有这样的功能:
$scope.process = function(){
$http().success(){
return something;
}
};
假设代码是完整的..然后当我调用它的时候
alert($scope.process());
它显示未定义。
如何让 angular 在继续之前等待函数返回?
最佳答案
你不知道。相反,您告诉它在响应可用时该怎么做:
$scope.process = function() {
$http.get(path).success(function(data) {
alert("I just received " + data);
});
};
或者,如果您希望它是可配置的:
$scope.process = function(callback) {
$http.get(path).success(callback);
};
关于javascript - 如何让 Angular 等待函数在继续之前返回一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17650185/