[英]Angular.js canceling $http requests inside bind() event
According to this https://github.com/angular/angular.js/issues/1159 根据这个https://github.com/angular/angular.js/issues/1159
this should work, shouldn't it? 这应该工作,不是吗?
el.bind('keyup', function() {
var canceler = $q.defer();
$http.post('/api', data, {timeout: canceler.promise}).success(success);
canceler.resolve();
});
because it doesn't fire the request at all, no errors or anything, could it be because it's inside a bind function? 因为它根本不会触发请求,没有错误或其他任何东西,可能是因为它在绑定函数内部吗?
it indeed was because it's inside the nonangular bind() event, putting scope.$apply()
after http and before resolve will fix it 确实是因为它在nonangular bind()事件内部,将
scope.$apply()
放在http之后,但在解析之前将其修复。
https://github.com/angular/angular.js/issues/1159#issuecomment-20368490 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();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.