Reputation: 1
when i remove ng-controller from view ,resolve property works perfectly fine but when i put ng-controller in template,it throws unknown provider.can any body help me out why this is happening??
app.config(['$routeProvider',function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'page/login.html',
controller: 'loginController',
resolve: {
message: function(demoService){
return demoService.getResolveContent();
},
greeting: function(demoFactory){
return demoFactory.getGreeting();
}
}
}).
when('/profile', {
templateUrl: 'page/profile.html',
controller: 'profileController'
})
.otherwise({
redirectTo: '/'
});
}]);
function loginController($scope,$location,message,greeting){
$scope.tempfactory = greeting; }
<div style="color: white;width: 100%;height: 100%;background-color: lightgray" ng-controller="loginController">
<p>{{tempfactory}}</p>
<input type="text" ng-model="inputBoxValue">
<button style="width: 100px;height: 100px" ng-click="profilePage()"></button>
</div>
If i replace above html with this:
<div style="color: white;width: 100%;height: 100%;background-color: lightgray" >
<p>{{tempfactory}}</p>
<input type="text" ng-model="inputBoxValue">
<button style="width: 100px;height: 100px" ng-click="profilePage()"></button>
</div>
It worked perfectly fine.can any body tell me the reason of this.
Upvotes: 0
Views: 69
Reputation: 42669
Dependencies added using resolve
are injected as part of route being resolved and controller being created and are not available otherwise. These are not global dependencies like a service
or filter
.
If you use ng-controller
the route transition does not happen and route related dependency resolution and controller creation does not take place and the DI error is raised.
If you put controller in route definition and using ng-controller
, two controller instances are created, but one gives DI error.
Upvotes: 2