I am using angular ui-router for an ionic application and here is my code. problem is controller initialization happens before the Level1Protocols could send data. What am I doing wrong?
$stateProvider
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
.state('tab.home', {
url: '/home',
views: {
'tab-home': {
resolve: {
Level1Protocols: ["Level1", "Protocol",function (Level1, Protocol) {
var protocolData = [],
protocol = new Protocol.Protocol(),
detailData = {};
Level1.loadProtocolData().success(function (response) {
for (var i = 0; i < response.length; i++) {
protocol.title = response[i].Title;
protocol.level = 1;
protocol.icon = Level1.getImageFromArray(response[i].Title);
protocolData.push(protocol);
}
console.log(protocolData);
return protocolData;
});
}]
},
templateUrl: 'templates/tab-home.html',
controller: ["$scope", "Level1Protocols", function ($scope, Level1Protocols) {
$scope.protocolData = Level1Protocols;
console.info("protocolData", $scope.protocolData); //This is executed before Level1Protocols return any data and hence undefined
}]
}
})