Angular.js取消了bind()事件中的$ http请求

时间:2013-07-02 18:57:06

标签: javascript jquery angularjs angularjs-directive angular-http

根据此https://github.com/angular/angular.js/issues/1159

这应该有用,不应该吗?

el.bind('keyup', function() {       
    var canceler = $q.defer();
    $http.post('/api', data, {timeout: canceler.promise}).success(success);
    canceler.resolve();
});

因为它根本不会触发请求,没有错误或任何错误,可能是因为它在绑定函数中?

1 个答案:

答案 0 :(得分:1)

确实是因为它在非角落的bind()事件中,将scope.$apply()放在http之后,在解析之前将修复它

https://github.com/angular/angular.js/issues/1159#issuecomment-20368490

el.bind('keyup', function() {       
    var canceler = $q.defer();
    $http.post('/api', data, {timeout: canceler.promise}).success(success);
    scope.$apply();
    canceler.resolve();
});