I have the following nested states for the ui-router
index.html
<body ng-app="testApp">
<div ui-view></div>
<body>
view.homepage.html
<div id="header" ng-controller="controllerHome">
<div id="middle">
<div ui-view>
<input type="text" ng-model="check">
<button ng-click="test()">Click</button>
</div>
</div
</div>
Here is my state definition js file
var testApp = angular.module('testApp',['ui.router']);
testApp.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.
otherwise('/');
$stateProvider
.state('home',
{
url:'/',
templateUrl : './templates/view.homepage.html',
controller : 'controllerHome',
resolve : {
userSession : function($http){
return $http({
method : "POST",
url : '/getSession'
});
}
}
})
})
homeController.js
testApp.controller('controllerHome',function($scope,$http,userSession){
$scope.check = "";
$scope.test = function(){
console.log($scope.check);
}
})
When I put the resolve I in the state definition I get the following error Error: $injector:unpr Unknown Provider.
So I tried removing the ng-controller directive but when I remove the ng-controller directive from the view, the value of $scope.check in the controllerHome is blank after click on the button.
I want to remove the ng-controller directive from the html view and put the resolve in the state definition.