Angularjs 重复使用模态和非模态角度控制器
我将如何为模态和非模态的目的重用角度控制器?我有一个新的业务需求,即在新页面的选项卡中放置与模态(仅模态体)中已经存在的表单相同的表单 目前,我正在模态初始化中使用Angularjs 重复使用模态和非模态角度控制器,angularjs,controller,angular-ui-bootstrap,Angularjs,Controller,Angular Ui Bootstrap,我将如何为模态和非模态的目的重用角度控制器?我有一个新的业务需求,即在新页面的选项卡中放置与模态(仅模态体)中已经存在的表单相同的表单 目前,我正在模态初始化中使用resolve将变量传递给模态的控制器 模式初始化 var modalInstance = $uibModal.open({ templateUrl: 'myModal.html', controller: 'myCtrl', resolve: { foo: function() { retur
resolve
将变量传递给模态的控制器
模式初始化
var modalInstance = $uibModal.open({
templateUrl: 'myModal.html',
controller: 'myCtrl',
resolve: {
foo: function() { return scope.fooFromScope; },
}
});
现有控制器
myApp.controller('hrpoConductReviewModalCtrl', ['$scope', 'foo', function($scope, foo) {
...
}]);
当前未在我的模态中使用$uibModalInstance
是否有方法从另一个控制器中初始化控制器并传递foo
变量?有一个现有的问题提出了同样的问题,但主要的答案是在模式初始化中使用范围
,而不是解析
。
现存问题:
如果您使用的是ui路由器,您只需使用“从ui路由器解析”即可:
$stateProvider
.state('conductReview', {
url: '/review',
templateUrl: '/js/templates/review.html',
controller: 'hrpoConductReviewModalCtrl',
resolve: {
foo: function() { return scope.fooFromScope; },
$uibModalInstance: function () { return null; } // <- workaround if you want to use $uibModalInstance in your controller.
}
})
$stateProvider
.状态(“conductReview”{
url:“/review”,
templateUrl:“/js/templates/review.html”,
控制器:“hrpoConductReviewModalCtrl”,
决心:{
foo:function(){return scope.fooFromScope;},
$uibModalInstance:function(){return null;}//我目前没有使用ui路由器,但一直认为这是我需要采用的路径。感谢$uibModalInstance:function(){return null;}
解决方法:)…+1