0

我只是尝试'ngTagsInput'在我的角度应用程序中使用,并且应用程序中的标签运行良好,但同时它在控制台中抛出错误。它不影响我的 UI 流程,但是是的错误正在控制台中记录。为什么原因和解决方案这个错误。错误:

Error: [$rootScope:inprog] $apply already in progress
http://errors.angularjs.org/1.2.6/$rootScope/inprog?p0=%24apply......

这是为浏览器下载我的文件的顺序

  <script type="text/javascript" src="js/ui-bootstrap.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.6/angular-resource.js"></script>
    <script type="text/javascript" src="js/ui-bootstrap-tpls.js"></script>
    <script src="js/angular-animate.min.js" ></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/angularjs-toaster/0.4.4/toaster.js"></script>
    <script type="text/javascript" src="js/angular-datatables.js"></script>
    <script type="text/javascript" src="js/loading-bar.js"></script>
    <script type="text/javascript" src="js/timer.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular-cookies.js"></script>
    <script src="//cdn.ckeditor.com/4.4.7/standard/ckeditor.js"></script>
    <script src="js/jquery-ui.js"></script>
    <script type="text/javascript" src="js/angular-sanitize.js"></script>
    <script type="text/javascript" src="../bower_components/angular-dragdrop/src/angular-dragdrop.min.js"></script>
    <script type="text/javascript" src="../bower_components/ng-tags-input/ng-tags-input.js"></script>

和我的看法

<tags-input ng-model="email_details.cc"></tags-input>

我的控制器

$scope.emailTemplates=[{
    'id'        :1,
    'cc'        :['developer@earning.com','a@rning.com'],
    'bcc'       :['ak@learning.com'],
    'subject'   :'1testing common template testing common template ' ,
    'created_on':'2015-07-04 16:04:02',
    'body'      :'body<b>hi'

},{
    'id'        :2,
    'cc'        :['cc2@rning.com','cc2@email.com'],
    'bcc'       :['bcc@email.com','bcc2@email.com'],
    'subject'   :'2testing common template testing common template ' ,
    'created_on':'2015-07-04 16:04:02',
    'body'      :'<p>a</p>'

}
]

在我使用 scope.watch/.eval/.apply 的地方有自定义指令

    .directive("myDatepicker", function () {
      return {
        restrict: "A",
        require: "ngModel",
        link: function (scope, elem, attrs, ngModelCtrl) {
          var updateModel = function (dateText) {
            scope.$apply(function () {
              ngModelCtrl.$setViewValue(dateText);
            });
          };
          var options = {
            dateFormat: "yy/mm/dd",
            onSelect: function (dateText) {
              updateModel(dateText);
            }
          };
          elem.datepicker(options);
        }
      }
    });
.directive("ngRandomClass", function () {
    return {
        restrict: 'EA',
        replace: false,
        scope: {
            ngClasses: "="
        },
        link: function (scope, elem, attr) {            

            //Add random background class to selected element
            elem.addClass(scope.ngClasses[Math.floor(Math.random() * (scope.ngClasses.length))]);
        }
    }
})
.directive('compile', function($compile) {
  return function(scope, element, attrs) {
    scope.$watch(
      function(scope) {
        return scope.$eval(attrs.compile);
      },
      function(value) {
        var result = element.html(value);
        //console.log(scope.$parent);
        $compile(element.contents())(scope.$parent.$parent);
      }
    );
  };
})
4

0 回答 0