This repository was archived by the owner on Apr 12, 2024. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 27.3k
    This repository was archived by the owner on Apr 12, 2024. It is now read-only.
  
  
Can no longer cancel $resource request with a promise #9332
Copy link
Copy link
Closed
Milestone
Description
I've tested this on Chrome 37.0.2062.124 m, Firefox 32.0.3, and IE11 on Windows 8.1
Here is some code to reproduce the issue.
<body ng-app="testApp">
    <div ng-controller="TestCtrl">
        <button type="button" ng-click="clear()">Clear</button>
        <ul>
            <li ng-repeat="val in dataset">
                {{val | json}}
            </li>
        </ul>
        <button type="button" ng-click="start()">Start</button>
        <button type="button" ng-click="stop()">Stop</button>
    </div>
    <script type="text/javascript" src="https://code.angularjs.org/1.3.0-rc.3/angular.js"></script>
    <script type="text/javascript" src="https://code.angularjs.org/1.3.0-rc.3/angular-resource.js"></script>
    <script type="text/javascript">
        angular.module('testApp', ['ngResource']).controller('TestCtrl', function ($scope, $resource, $q) {                                   
            var promises = [];
            function getResource() {
                var defered = $q.defer();
                promises.push(defered);
                return $resource('/data', {}, {
                    query: {
                        method: 'GET',
                        isArray: true,
                        timeout: defered.promise
                    }
                });
            }
            $scope.start = function () {
                getResource().query(function (res) {
                    $scope.dataset = res;
                });
            };
            $scope.stop = function () {
                promises.forEach(function (p) { p.resolve(); });
                promises = [];
            };
            $scope.clear = function() {
                $scope.dataset = [];
            }
        });
    </script>
</body>23bc92b appears to be the culprit. Before this the above code works as expected.