Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

10 $digest() iterations reached when get options from service by method! #400

@sszdh

Description

@sszdh

Hi,
I have a constant service in my app to store some global configs and options.

(function() {

    'use strict';

    angular.module('App.Core')

        .factory('Constants', ['$rootScope', function($rootScope) {

            return {
                getUiSortableOptions: function() {
                    return {
                        axis: "y",
                        handle: ".handle",
                        items: "> .movable",
                        containment: 'parent',
                        revert: 50,
                        tolerance: 'pointer',
                        opacity: 0.8,
                        cursor: 'move'
                    };
                }
            };
        }])
})();

And in my CoreCtrl I register a global scope's variable for access in view:

(function() {

    'use strict';

    angular.module('App.Core')

    /**
     * Main site controller
     */
        .controller('CoreCtrl', [ '$scope', 'Constants', function ( $scope, Constants) {
            $scope.constants = Constants;
        }])
    ;
})();

View:

<div ui-sortable="constants.getUiSortableOptions()">
....
....
</div>

But in console I receive 10 $digest() iterations reached error:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":{"axis":"y","handle":".handle","items":"> .movable","containment":"parent","revert":50,"placeholder":"ui yellow message","tolerance":"pointer","opacity":0.8,"cursor":"move"},"oldVal":{"axis":"y","handle":".handle","items":"> .movable","containment":"parent","revert":50,"placeholder":"ui yellow message","tolerance":"pointer","opacity":0.8,"cursor":"move"}}],[{"msg":"fn: regularInterceptedExpression","newVal":{"axis":"y","handle":".handle","items":"> .movable","containment":"parent","revert":50,"placeholder":"ui yellow message","tolerance":"pointer","opacity":0.8,"cursor":"move"},"oldVal":"..."}],[{"msg":"fn: regularInterceptedExpression","newVal":{"axis":"y","handle":".handle","items":"> .movable","containment":"parent","revert":50,"placeholder":"ui yellow message","tolerance":"pointer","opacity":0.8,"cursor":"move"},"oldVal":"..."}],[{"msg":"fn: regularInterceptedExpression","newVal":{"axis":"y","handle":".handle","items":"> .movable","containment":"parent","revert":50,"placeholder":"ui yellow message","tolerance":"pointer","opacity":0.8,"cursor":"move"},"oldVal":"..."}],[{"msg":"fn: regularInterceptedExpression","newVal":{"axis":"y","handle":".handle","items":"> .movable","containment":"parent","revert":50,"placeholder":"ui yellow message","tolerance":"pointer","opacity":0.8,"cursor":"move"},"oldVal":"..."}]]

So when I change CoreCtrl & View as follow, everything works perfectly!

$scope.sortableOptions = Constants.getUiSortableOptions();
<div ui-sortable="sortableOptions">
....
....
</div>

Demo

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions