Angularjs 如何解决错误:[$rootScope:infdig]10$digest()已达到迭代次数。流产?

Angularjs 如何解决错误:[$rootScope:infdig]10$digest()已达到迭代次数。流产?,angularjs,cookies,gruntjs,Angularjs,Cookies,Gruntjs,我需要设置和获取cookie值,为此我使用以下代码。但这是一个错误。我怎样才能解决这个问题 我的代码 angular.module('appmodule',['ngCookies']).controller('myctl',function ( $rootScope, $cookieStore) { var vm = this; var lastVal = $cookieStore.get('lastValue'); if (!lastVal) { $r

我需要设置和获取cookie值,为此我使用以下代码。但这是一个错误。我怎样才能解决这个问题

我的代码

angular.module('appmodule',['ngCookies']).controller('myctl',function ( $rootScope, $cookieStore) {

var vm = this;
var lastVal = $cookieStore.get('lastValue');
        if (!lastVal) {
            $rootScope.lastVal = 1;
        } else {
            $rootScope.lastVal = lastVal + 1;
        }
        $cookieStore.put('lastValue', $rootScope.lastVal);
});
错误

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [null,[{"msg":"fn: ngModelWatch"},                 {"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":true},{"msg":"fn: expressionInputsWatch","newVal":true},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{}},{"msg":"fn: ngModelWatch"},{"msg":"vm.showConfrimError"},{"msg":"fn: expressionInputWatch","newVal":{}},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":true},{"msg":"fn: expressionInputsWatch","newVal":true},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}}],null,[{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":true},{"msg":"fn: expressionInputsWatch","newVal":true},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{}},{"msg":"fn: ngModelWatch"},{"msg":"vm.showConfrimError"},{"msg":"fn: expressionInputWatch","newVal":{}},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":""},{"msg":"fn: expressionInputWatch","newVal":true},{"msg":"fn: expressionInputsWatch","newVal":true},{"msg":"fn: ngModelWatch"},{"msg":"fn: expressionInputWatch","newVal":{"has-error":false}}]]
http://errors.angularjs.org/1.3.20/$rootScope/infdig?p0=10&p1=%5Bnull%2C%5B%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputsWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22vm.showConfrimError%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputsWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%5D%2Cnull%2C%5B%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputsWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22vm.showConfrimError%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%7D%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%22%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputsWatch%22%2C%22newVal%22%3Atrue%7D%2C%7B%22msg%22%3A%22fn%3A%20ngModelWatch%22%7D%2C%7B%22msg%22%3A%22fn%3A%20expressionInputWatch%22%2C%22newVal%22%3A%7B%22has-error%22%3Afalse%7D%7D%5D%5D

请帮助我,提前谢谢。

您能添加相应的视图html吗?是的,删除cookie内容后,它工作正常。但是,为set或get cookie值编写代码是错误的,创建一个演示来复制这个问题