Angularjs 缩小时的Ui路由器模式注入错误
我正在使用ui路由器和ui引导/模式 我有一个销售屏幕分为2,所以我有一个左侧的购物车和右侧可以有目录,编辑产品或付款部分 我需要在所有状态下都有一个模式,所以我创建了一个函数来添加一些ui路由器状态。 下面是函数:Angularjs 缩小时的Ui路由器模式注入错误,angularjs,angular-ui-bootstrap,angular-ui-router,bootstrap-modal,Angularjs,Angular Ui Bootstrap,Angular Ui Router,Bootstrap Modal,我正在使用ui路由器和ui引导/模式 我有一个销售屏幕分为2,所以我有一个左侧的购物车和右侧可以有目录,编辑产品或付款部分 我需要在所有状态下都有一个模式,所以我创建了一个函数来添加一些ui路由器状态。 下面是函数: var modalSaleDelete = ['$state', '$modal', function($state, $modal) { $modal.open({ templateUrl: 'views/sale/delete.html',
var modalSaleDelete = ['$state', '$modal',
function($state, $modal) {
$modal.open({
templateUrl: 'views/sale/delete.html',
resolve: {
parentScope: function($rootScope) {
return $rootScope.parentScope;
}
},
controller: function($scope, parentScope) {
$scope.delete = function() {
// TODO: change the way this is called
parentScope.resetOrder();
parentScope = null;
$scope.$close('cancel');
};
$scope.cancel = function() {
parentScope = null;
$scope.$dismiss('cancel');
};
}
}).result.then(function() {
return $state.transitionTo($state.$current.parent);
}, function() {
return $state.transitionTo($state.$current.parent);
});
}
];
然后我把它放在每个州:
.state('sale.new.catalog.delete', {
url: '/delete',
onEnter: modalSaleDelete
})
它在开发中非常有效,但当我缩小它时,我会出现一个错误:
Error: [$injector:unpr] Unknown provider: aProvider <- a
http://errors.angularjs.org/1.2.24/$injector/unpr?p0=aProvider%20%3C-%20a
at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:3:26944
at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:11462
at Object.c [as get] (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:10723)
at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:11557
at c (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:10723)
at Object.d [as invoke] (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:11008)
at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:8:20044
at Object.f [as forEach] (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:3:27387)
at j (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:8:19961)
at Object.k.open (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:8:20414)
错误:[$injector:unpr]未知提供程序:aProvider尝试通过创建inject属性手动注入它们。您是否设置了JSFIDLE或PLUNK
modalSaleDelete.$inject = ['$state', '$modal'];
您需要对每个注入进行注释,以使缩小生效。或者,如果您使用的是角度感知缩微器,它可能不知道哪些函数是由UI路由器注入的,哪些是标准函数
var modalSaleDelete = ['$state', '$modal',
function($state, $modal) {
$modal.open({
templateUrl: 'views/sale/delete.html',
resolve: {
parentScope: [ '$rootScope', function($rootScope) {
return $rootScope.parentScope;
}]
},
controller: [ '$scope', 'parentScope', function($scope, parentScope) {
$scope.delete = function() {
// TODO: change the way this is called
parentScope.resetOrder();
parentScope = null;
$scope.$close('cancel');
};
$scope.cancel = function() {
parentScope = null;
$scope.$dismiss('cancel');
};
}]
}).result.then(function() {
return $state.transitionTo($state.$current.parent);
}, function() {
return $state.transitionTo($state.$current.parent);
});
}
];
嗯,我已经弄明白了。我不明白为什么,但问题已经解决了。
我在resolve中使用“$state”解决了它,尽管它不是必需的。
调试时,我刚刚看到aProvider正试图被注入其中
var modalSaleDelete = ['$rootScope', '$state', '$modal',
function($rootScope, $state, $modal) {
$modal.open({
templateUrl: 'views/sale/delete.html',
resolve: {
parentScope: ['$state', '$rootScope', function($state, $rootScope) {
return $rootScope.parentScope;
}]
},
controller: ['$scope', '$state', 'parentScope', function($scope, $state, parentScope) {
$scope.delete = function() {
// TODO: change the way this is called
parentScope.resetOrder();
parentScope = null;
$scope.$close();
};
$scope.cancel = function() {
parentScope = null;
$scope.$dismiss();
};
}]
}).result.then(function() {
// close
return $state.transitionTo($state.current.name.replace('.delete', ''));
}, function() {
// dismiss
return $state.transitionTo($state.current.name.replace('.delete', ''));
});
}
];
我实际上使用的是一个角度感知缩微器,正如你所说的,我需要在正确的位置注入$state。问题在于找到它,因为堆栈只显示供应商函数,所以我真的不知道从哪里开始调试我的部件。不过谢谢你的帮助