I am using angular-ui-router, and I have multiple ui-view divs as shown below:
<!DOCTYPE html>
<html ng-app="myApp">
<!-- loading libraries here etc -->
<div ui-view="viewA"></div>
</html>
Each view has it's own controller, and I need to resolve dependencies passed into these controllers. I have tried the following and am stumped as to why it is not working:
var myApp = angular.module('myApp', ['ui.router']);
myApp.config(function($stateProvider) {
$stateProvider
.state('index', {
url: "",
views: {
"viewA": {
template: "{{test}}",
resolve: {
test: function(){
return {
value: 'Hello World!'
};
}
},
controller: testController
},
}
});
});
myApp.controller('testController', function($scope, test){
$scope.test = test.value;
});
I have created a plunker here.
It doesn't matter whether I declare the controller before or after I call config. Putting the controller inline does work, but this would get unwieldy and difficult to maintain over time, I want to store it in it's own file.
I was under the impression that angular was smart enough to wait for dependencies to load while bootstrapping your app, is this not the case? Is the only way to put my controller inline?
Thanks