javascript - 为什么我在 Angular JS 中使用解析时出现错误?

标签 javascript angularjs angularjs-directive angularjs-scope ionic-framework

我正在尝试使用resolve。这意味着我需要在加载 Controller 和 View 之前从服务获取数据。我找到了一些如何使用resolve的行。

当我删除解析语句时,我的项目中没有出现错误

.state('a', {
      url: "/a",
      templateUrl: "a.html",
          controller: 'a',
          // resolve:{
          //   messsage:function(testservice){
          //     return testservice.getdata();
          //   }
          //}
      })

当我取消注释解析语句时,出现此错误

**Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D
    at REGEX_STRING_REGEXP (ionic.bundle.js:8762)
    at Scope.promises.$get.Scope.$digest (ionic.bundle.js:22980)
    at Scope.promises.$get.Scope.$apply (ionic.bundle.js:23205)
    at done (ionic.bundle.js:18358)
    at completeRequest (ionic.bundle.js:18548)
    at XMLHttpRequest.requestLoaded (ionic.bundle.js:18489)(anonymous function) @ ionic.bundle.js:20306jqNodes.$get @ ionic.bundle.js:17256promises.$get.Scope.$apply @ ionic.bundle.js:23207done @ ionic.bundle.js:18358completeRequest @ ionic.bundle.js:18548requestLoaded @ ionic.bundle.js:18489
ionic.bundle.js:8762 Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5DREGEX_STRING_REGEXP @ ionic.bundle.js:8762promises.$get.Scope.$digest @ ionic.bundle.js:22980promises.$get.Scope.$apply @ ionic.bundle.js:23205done @ ionic.bundle.js:18358completeRequest @ ionic.bundle.js:18548requestLoaded @ ionic.bundle.js:18489
ionic.bundle.js:20306 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D
    at REGEX_STRING_REGEXP (ionic.bundle.js:8762)
    at Scope.promises.$get.Scope.$digest (ionic.bundle.js:22980)
    at Scope.promises.$get.Scope.$apply (ionic.bundle.js:23205)
    at done (ionic.bundle.js:18358)
    at completeRequest (ionic.bundle.js:18548)
    at XMLHttpRequest.requestLoaded**

这是我的代码 http://plnkr.co/edit/fk7IGcYlDfZasWqzy31S?p=preview

我正在尝试在 Controller 中使用之前和加载查看之前从服务加载数据

最佳答案

为您的服务使用良好的语法

factory('testservice', ['$http',
    function testservice($http) {

获取 Controller 中的数据:

$scope.data = testservice.getdata();

plnk: http://plnkr.co/edit/2EskRAzVPo8lhXyaLFuy?p=preview

那么您应该考虑在服务中备份您的数据,以便您调用 $http.get("data.json") 一次。

关于javascript - 为什么我在 Angular JS 中使用解析时出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32798498/

相关文章:

angularjs - 如何从AngularJS中资源的查询方法的返回中获取数组?

javascript - 如何使用java脚本或jquery从php选择项获取值,其中选择项值来自查询mysql

javascript - 确定哪个框架(名称)调用了 JavaScript 中的函数

javascript - Mongodb javascript 表达式和 $where

javascript - jquery 滚动功能无法正常工作

javascript - 临时局部变量的 Angular 指令

javascript - angularjs中的递归嵌套指令

javascript - 没有依赖关系的 AngularJS 的简单框架

javascript - Angular ng-init 函数在指令后加载

javascript - 使用 Angular 格式化程序/解析器