angular ui router - Resolve data not being found in controller AngularJS -


suppose have 1 route:

angular.module('liveapp', ['ui.router',                           'liveapp.main',                           'liveapp.artist',                           'liveapp.signup',                           'liveapp.factory',                           'liveapp.review'                           ])  .config(function($urlrouterprovider, $stateprovider) { $stateprovider.state("home", {                 url:"/",                 templateurl : '/home.html',                 controller  : 'mainctrl',                 resolve: {                     artists: function () {                       console.log('resolved')                       return "i want in controller";                      }                   }                     }) }) 

prior instantiation of mainctrl want function bound artists run. in controller have following setup:

angular.module('liveapp.main',['liveapp.factory']) .controller('mainctrl', ['$rootscope','$scope','$http', '$location','datafactory','artists', mainctrl])  function mainctrl($rootscope,$scope,$http,$location,datafactory,artists){   console.log(artists) //expect return resolve in ui.router }     

when console logging artists evaluated undefined. have idea why is?

were using ui-view? if yes should not have ng-controller mainctrl. have made minor tweaks , code works fine

angular.module('liveapp', ['ui.router', 'liveapp.main'])    .config(function($urlrouterprovider, $stateprovider) {    $stateprovider.state("home", {      url:"/",      templateurl : 'home.html',      controller  : 'mainctrl',      resolve: {        artists: function () {          console.log('resolved');          return "i want in controller";        }      }    });  });    angular.module('liveapp.main',[])    .controller('mainctrl', ['$rootscope','$scope','$http', '$location', 'artists', mainctrl]);    function mainctrl($rootscope,$scope,$http,$location, artists){    console.log(artists); //expect return resolve in ui.router  }  
<!doctype html>  <html lang="en" ng-app="liveapp">  <head>      <meta charset="utf-8">      <title></title>  </head>  <body>      <div ui-view></div>        <script type="text/ng-template" id="home.html">      lorem ipsum    </script>        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>      <script src="http://rawgit.com/angular-ui/ui-router/0.2.15/release/angular-ui-router.js"></script>      <script src="index.js" type="text/javascript"></script>  </body>  </html>


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -