Last active
October 4, 2016 12:48
-
-
Save zmts/98941e63eb9ac3241f0322bec1ea4e23 to your computer and use it in GitHub Desktop.
Pass some data(resp) from resolve in router to controller (Angular1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
angular | |
.module('app') | |
.controller('MyController', function ($scope, $state, $log, SomeService) { | |
var vm = this; | |
vm.list = $state.resp; | |
}); | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
angular | |
.module('app') | |
.config(routesConfig); | |
/** @ngInject */ | |
function routesConfig($stateProvider, $urlRouterProvider, $locationProvider) { | |
$locationProvider.html5Mode(true).hashPrefix('!'); | |
$urlRouterProvider.otherwise('/'); | |
$stateProvider | |
.state('app', { | |
url: '/', | |
component: 'app' | |
}) | |
.state('my', { | |
url: '/my', | |
templateUrl: 'app/mydirective/mydirective.html', | |
controller: 'MyController', | |
controllerAs: 'myctrl', | |
resolve: { | |
initDataList: function ($state, $log, SomeService) { | |
return SomeService.fetchDataList().then(function (resp) { | |
$state.resp = resp; | |
}, function (err) { | |
$log.log('error', err); | |
}); | |
} | |
} | |
}) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment