Angular js / angular ui router 0.2.15
我试图使用$ state.go将复杂的js数组传递给控制器 以下是我的代码可以帮助你。看起来像下面的代码抛出错误
错误:[$ injector:unpr] http://errors.angularjs.org/1.2.28/ $ injector / unpr?p0 = servicesProvider%20%3C-%20services
var services = {complex type};
$state.go("linearOfferProcess", {'services': services});
state('linearOfferProcess', {
url: '/linearOfferProcessor',
templateUrl: '/partials/linear_process.html',
controller: 'linearProcessController',
services:
function($stateParams) {
return $stateParams.services;
}
}
angular.module('app').controller('linearOfferProcessController',function($scope) {
$scope.services = services;
});
答案 0 :(得分:0)
不幸的是,我不知道有任何可能实现这一点,但你可以尝试使用工厂。我为你做了一个小模型,在容器中我存储服务并为每个复杂对象创建一个唯一的ID。所以你可以随时检索它。
angular.module('app').factory('ServicesContainer', function() {
var counter = 1;
return {
container: {},
add: function(services) {
container[counter] = services;
return counter;
}
};
});
angular.module('app').controller('SomeController', function(ServicesContainer, $state) {
var id = ServicesContainer.add({ complex object });
$state.go('services', {
id: id
});
});
angular.module('app').config(function($stateProvider) {
$stateProvider.state('services', {
url: '/{id}',
onEnter: function(ServicesContainer, $stateParams, $log) {
$log.info('Services', ServicesContainer[$stateParams.id]);
}
});
});