AngularJS 10 $ digest()迭代达成。中止

时间:2016-04-13 12:15:19

标签: javascript angularjs

我正在使用angular 1.4来调用REST API,但我得到了

  

达到了AngularJS 10 $ digest()迭代次数。中止

这是我的services.js

(function (angular) {
'use strict';

angular.module('myApp.services.dashboard', [])
        .factory('DashboardService', DashboardService);

DashboardService.$inject = ['$http', '$q', 'EndpointUrl'];

function DashboardService($http, $q, EndpointUrl) {
    function getStatus() {
        var deferred = $q.defer();

        return $http.get(EndpointUrl + 'status')
                .then(successRequest, failRequest);

        function successRequest(data) {
            deferred.resolve(data.data);
            return deferred.promise;
        }
        ;

        function failRequest() {
            deferred.reject([]);
            return deferred.promise;
        }
        ;
    };
};

})(angular);

这是我的app.js

.config(function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider, $compileProvider) {
                $locationProvider.html5Mode(false).hashPrefix('!');
                $compileProvider.debugInfoEnabled(false);

                $stateProvider
                        .state('dashboard', {
                            controller: 'DashboardController as dashboard',
                            url: '/app/dashboard',
                            templateUrl: '/assets/js/src/dashboard/templates/dashboard.html',
                            resolve: {
                                getStatus: function (DashboardService) {
                                    return DashboardService.getStatus();
                                }
                            }
                        });

                $urlRouterProvider.otherwise('/app/dashboard');
                $httpProvider.defaults.useXDomain = true;
                delete $httpProvider.defaults.headers.common['X-Requested-With'];
            })

我的controller.js没有执行任何操作:

(function (angular) {
    'use strict';
    angular.module('myApp.controllers.dashboard', [])
            .controller('DashboardController', DashboardController);
    DashboardController.$inject = ['$rootScope', '$state', '$filter', 'DashboardService', 'DashboardPeriods', 'getStatus'];
    function DashboardController($rootScope, $state, $filter, DashboardService, DashboardPeriods, getStatus) {

    }
    ;

})(angular);

所以我真的不明白为什么我得到了$ digest()迭代次数 REST API只返回每次都相同的json。

1 个答案:

答案 0 :(得分:0)

您正在返回$ http Promise,然后从您的回调中返回deferred.promise,这可能会导致循环。删除$ http返回。将deferred.promise返回调用返回方法,并从getStatus方法返回。

Failed to load resource: net::ERR_CONNECTION_REFUSED