These are chat archives for filearts/plunker

18th
May 2016
Vương Thái
@vuongthai91
May 18 2016 09:15

var app = angular.module('myApp', ['ui.router']);

app.config(function($stateProvider, $urlRouterProvider) {

$stateProvider

.state('state1', {
url: '/state1?foo&bar',
controller: 'MainCtrl',
templateUrl: 'template.html',

resolve: {
  resolvedParams: function(ResolveParamsFactory1, $stateParams) { // 1) Inject $stateParams inside resolve
    return ResolveParamsFactory1($stateParams);
  }
}

})

.state('state2', {
url: '/state2?foo&bar',
controller: 'MainCtrl',
templateUrl: 'template.html',

resolve: {
  resolvedParams: 'ResolveParamsFactory2'
}

})

$urlRouterProvider.otherwise('/state1');
});

app.factory('ResolveParamsFactory1', function() { // 1) Don't inject $stateParams inside factory
return function(params) {
return _.clone(params);
};
});

app.factory('ResolveParamsFactory2', ['$stateParams', function($stateParams) { // 2) Inject $stateParams inside factory
return $stateParams;
}]);

app.controller('MainCtrl', function($scope, $stateParams, resolvedParams) {
$scope.$stateParams = $stateParams;
$scope.resolvedParams = resolvedParams;
});