简体   繁体   English

为什么在angular js中使用resolve时出现错误?

[英]why i am getting error while using resolve in angular js?

I am trying to use resolve .Mean I need to get data from service before loading the controller and view .I found some line how to use resolve . 我正在尝试使用resolve。意味着我需要在加载控制器和查看之前从服务获取数据。我发现了一些如何使用resolve的行。

I an not getting error in my project when I remove resolve statement 删除resolve语句时,我的项目没有出现错误

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

when I uncomment the resolve statement I got this error 当我取消注释resolve语句时,出现此错误

**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**

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

I am trying to load data from service before using in controller and before loading to view 我正在尝试在控制器中使用和加载以查看之前从服务加载数据

Use the good syntax for your service 为您的服务使用良好的语法

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

Fetch the data in your controller : 在您的控制器中获取数据:

$scope.data = testservice.getdata();

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

Then you should consider backing your data in the service so you call $http.get("data.json") one time. 然后,您应该考虑在服务中备份数据,以便一次调用$http.get("data.json")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 angular.min.js 中收到此错误 - Why am i getting this error in the angular.min.js 在构建angular-6应用程序时出现此错误,我该如何解决呢? - While making a build of angular-6 application am getting this error how i can resolve this? 为什么我收到这个JS错误? - Why am I getting this JS error? 为什么我在使用 useState 作为数组时出现错误 - why i am getting an error while i am using useState as an array 我在使用 nodemailer 时遇到错误 - i am getting error while using nodemailer 为什么在抓取JavaScript时出现500错误 - Why am I am getting 500 Error while crawling in javascript 为什么我在Angular JS中获得两个方法调用? - Why am I getting two method calls in Angular JS? 我收到错误消息:TypeError:使用Parse API更新用户对象时,e.changes未定义。 如何解决呢? - I am getting an error: TypeError: e.changes is undefined while updating the user object using Parse API. How to resolve this? 在使用 transaction.wait() 时,我在 ether js 中收到一个事务被替换错误 - I am getting a transaction was replaced error in ether js while using transaction.wait() 为什么在这里出现Angular $ injector:modulerr错误? 使用1.5 Beta - Why am I getting the Angular $injector:modulerr error here? Using 1.5 beta
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM