I have a situation here, where inside one state, I have multiple views and each view has to fetch data from the server side, so I wanted to use 'resolve' in every view which makes its own REST call to get data from the server.
Following is my attempt :
.state('dashboard.xyz.deal.details', {
url: "/details/:dealId",
resolve: {
permissions : function(dealDetails, $stateParams){
return dealDetails.getUnitPermissions($stateParams.dealId);
}
},
views: {
"viewDealDetails": {
templateProvider: function(permissions, $http){
return $http.get('/modules/deal-details-module/partial/views/view-deal-details/view-deal-details.html')
.then(function(tpl){
return tpl.data;
});
},
controller: 'ViewDealDetailsCtrl',
resolve: {
resolveDealDetails : function(dealDetails, $stateParams){
console.log('Inside the resolve of viewDealDetails');
return dealDetails.getDealDetails($stateParams.dealId);
}
}
},
"viewFinePrints": {
templateProvider: function(permissions, $http){
return $http.get('/modules/deal-details-module/partial/views/view-fine-prints/view-fine-prints.html')
.then(function(tpl){
return tpl.data;
});
},
resolve: {
resolveFinePrints: function(dealDetails){
//How can I inject the 'resolveDealDetails' as dependency in 'resolveFinePrints' ?
console.log('Inside the resolve of resolveFinePrints ::::::');
return dealDetails.getFinePrints('travel').then(function(data){
return data;
});
}
},
controller: 'ViewFinePrintsCtrl'
}
}
})
So, I wanted to ask following questions :
Q1. Is it correct to use 'resolve' inside the multiple views? As I have read it from the official documentation that
The resolve keyword MUST be relative to state not views (in case you use multiple views).
Q2. If resolving the dependencies in the views is OK, then how can I insert one resolved dependency inside another view ?
For eg. in my code I want use 'resolveDealDetails' as the dependency for 'resolveFinePrints'