Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Last active January 15, 2016 15:23
Show Gist options
  • Save auxcoder/d0fe2262caa974ce8322 to your computer and use it in GitHub Desktop.
Save auxcoder/d0fe2262caa974ce8322 to your computer and use it in GitHub Desktop.
ui-router-with-resolve-example
(function() {
'use strict';
angular
.module('myApp')
.config(routeConfig);
/** @ngInject */
function routeConfig($stateProvider, $urlRouterProvider) {
$stateProvider
.state('proposal', {
url: "/proposal",
// abstract: true,
templateUrl: "app/proposal/proposal.html",
controller: 'ProposalController',
controllerAs: 'proposal',
onEnter: function(){
console.log('proposal');
}
})
.state('proposal.equipment', {
url: '/equipment',
title: 'Proposal Equipment',
views: {
'': {
templateUrl: 'app/proposal/equipment/proposal.equipment.html',
controller: 'ProposalUpdateEquipmentController',
controllerAs: 'equipment'
},
'navbar@proposal.equipment': {
templateUrl: 'app/proposal/navbar/proposal.navbar.html',
controller: 'ProposalNavbarController',
controllerAs: 'navbar'
}
},
resolve: {
currentSystemData: function($http, $q, API, localStorageService){
var proposal = localStorageService.get('proposal');
var params = {customerLocationId: proposal.customer_location_id, serviceProviderId: proposal.provider_id};
var deferred = $q.defer();
$http({method: 'GET', url: API + '/customer/currentsystemdetails', params: params})
.then(
function(response) {
var data = response;
// console.log(response);
deferred.resolve(data.data.payLoad);
},
function(response) {
console.log(response);
deferred.reject();
}
);
return deferred.promise;
}
},
onEnter: function(){
console.log('proposal.equipment');
}
});
$urlRouterProvider.otherwise('/');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment