javascript - Angular 传递回调以 promise

标签 javascript angularjs

如何将要由 promise 处理的回调作为参数传递给调用函数?例如,我有

$scope.caller = function() {
    $http({...}).then(successCallback(response) {
        ...
    }, function errorCallback(response) {
        ...
    });
}

我如何将匿名函数传递给 $scope.caller() 以便在 promise 完成时进行评估?

最佳答案

您可以将您的函数作为参数传递给 $scope.caller。

$scope.caller = function (somefunc) {
     $http(..).then(somefunc));
};

关于javascript - Angular 传递回调以 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38881501/

相关文章:

javascript - ng-switch 对动态值变化没有反应

javascript - 初始化 AngularJS Controller 时出现问题 : Cannot set property . .. 未定义

angularjs - ng-sortable 如何在项目重新排序时获取列表 id

javascript - multer上传不工作

javascript - 在 HTML5/Javascript 移动应用程序中下载 PDF 文件

javascript - 打开 jquery 对话框时保持滚动位置

javascript - Kendo UI 网格 - 分组表标题

javascript - 在 Angular 中缩短 Linky

javascript - 如何获取单击元素的类值并使用此值在 jquery 中此类最后一次出现后放置一段 html 代码

css - 如何更改 angularJS 的默认 css 样式?搜索框等