Reputation: 1286
i m using angular ui-router and to get data before initiating Controller m using resolve
.state('Equipment', {
url: "/equipment",
templateUrl: "/Scripts/app/equipment/templates/content.html",
resolve: {
equipmentService: 'EquipmentService',
data: function (equipmentService) {
return equipmentService.getEquipment().$promise;
}
},
controller: 'EquipmentController'
})
and in equipmentService i m doing
resource.equipment.getEquipment().$promise.then(function (response) {
_equipment.collection = _.map(response.data, function (item) {
var obj = {
id: item.id,
name: item.name,
groupId: item.equipmentGroupId,
groupName: item.equipmentGroupName,
description: item.description
}
return obj;
});
return _equipment.collection;
});
on response from server service object gets updated but state doesn't change neither controller gets initiated
and if i change it with
return resource.equipment.getEquipment();
now on server response controller gets initiated but service doesnt as i m using service to share data between controllers. i have to update service object literal
can some one help me what i m doing wrong
Upvotes: 0
Views: 195
Reputation: 3988
I think there is a better option here. You can use this service as a model once the data is retrieved from the server and for that define a variable(property) in service. check out the following question. ui-route resolve not working
Upvotes: 0