-2

I would like to load my data before the route changes and using

$routeChangeSuccess

or

$routeChangeStart 

will not help and would like to do it using resolve in angular routing. So when ever a route change, i use resolve and load the data and when that is done i have the data ready to be bound on the templateUrl that the route will serve

i am not sure if i am doing this correct but can any one please explain why this plnk is not working

narcs
  • 213
  • 1
  • 2
  • 13

1 Answers1

0

You are not injecting the 'mydata' into your controller. I suggest using two controllers, since mydata is not defined until you resolve the route.

var CampaignController = function ($scope, mydata) {
  $scope.mydata = mydata;
};
var mainController = function ($scope) {
  $scope.mydata = "mydata";
};
CampaignController.$inject = ['$scope', 'mydata'];
mainController.$inject = ['$scope'];

var ngApp = angular.module('ngApp', ['ngRoute']);
ngApp.controller('CampaignController', CampaignController);
ngApp.controller('mainController', mainController);

here is an updated plnk

joshvito
  • 1,498
  • 18
  • 23
  • although it works, i dont see this [link](http://odetocode.com/blogs/scott/archive/2014/05/20/using-resolve-in-angularjs-routes.aspx) wrapping a controller inside another one.. can you please also explain how it works there? – narcs Apr 08 '15 at 12:49