我正在尝试使用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/