AngularJS - $ cancelRequest not available in $ resource

I am trying to start an interrupt request, but I am not getting the object $cancelRequestas a result $resource. But I can get objects $promiseand $resolved.

Why is this happening? How can i get this $cancelRequest?

PS: I am using AngularJS 1.5

The UPDATE . After some trial and error, I found that it does not work just because I used AngularJS 1.5 rc 0. Now that I used AngularJS 1.5 rc 2., which is the last one, it just worked.

+4
source share
1 answer

According to the documentation, it is only available for Angular 1.5 :

$cancelRequest: , , , .

Angular 1.4...

1.5, rc-1...

, $resource, :

, $resourceProvider. :

stripTrailingSlashes - {boolean} - true, URL- . ( true). cancelable - {boolean} - true, , "-" ( ) $cancelRequest() . . ( false.)

<html ng-app="test">
<head>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.1/angular-resource.min.js"></script>

<script>
angular.module('test', ['ngResource'])
.config(function($resourceProvider) {
    $resourceProvider.defaults.cancellable = true;
})
.factory('Resource', function($resource) {
    return $resource('api/test', {}, {
        test: { cancellable : true }
    });
})
.controller('myController', function($scope, Resource) {
    Resource.query().$cancelRequest(); // ok 
    Resource.test().$cancelRequest(); // ok
});

</script>

</head>
<body ng-controller="myController">

</body>
</html>
+8

Source: https://habr.com/ru/post/1626398/


All Articles