gpt4 book ai didi

angularjs - Angular Calling Modal Open 功能从一个 Controller 到另一个 Controller

转载 作者:行者123 更新时间:2023-12-03 06:59:26 24 4
gpt4 key购买 nike

我的标题中有一个模态窗口,标题中有一个单击事件链接来打开和关闭模态窗口...这工作正常。即

<div class="header" ng-controller="headerCtrl">
...
<li><a href ng-click="open()">Report an Issue</a></li>
...
</div>

然后是我的 Controller

 .controller('headerCtrl', ['$location', '$scope', '$log', '$modal', function ($location, $scope, $log, $modal) {
'use strict';
(function () {// init
$scope.open = function (size) {
var modalInstance = $modal.open({
templateUrl: 'views/help/supportModalContent.html',
controller: 'supportInstanceCtrl'
});
};
})();
}])

.controller('supportInstanceCtrl', ['$location', '$scope', '$log', '$modalInstance','$state', function ($location, $scope, $log, $modalInstance,$state) {
'use strict';
(function () {// init
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.isCollapsed = false;
$scope.message_sent = false;
})();

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};

$scope.faq = function () {
$modalInstance.close('cancel');
$state.go('faq');
};

$scope.help = function () {
$modalInstance.close('cancel');
$state.go('help');
};

$scope.send = function () {
$scope.isCollapsed = true;
$scope.message_sent = true;
};
}])

问题现在出现在我的主要内容 View 之一中,现在我下面还有一个链接,上面写着单击此处获取支持。我想再次打开相同的模式窗口。所以我这样做了

  .controller('noResultCtrl', ['$location','$scope','$log','search','$state','$modal',function ($location,$scope,$log,search,$state,$modal) {
'use strict';
$scope.open = function (size) {
var modalInstance = $modal.open({
templateUrl: 'views/help/supportModalContent.html',
controller: 'supportInstanceCtrl'
});
};
}])

它可以工作,但是有没有更好的方法,而不是必须将相同的逻辑放入我想在标题中调用相同模态窗口的每个 Controller 中?

最佳答案

app.service('modalProvider',['$modal', function ($modal){

this.openPopupModal= function() {
var modalInstance = $modal.open({
templateUrl: 'views/help/supportModalContent.html',
controller: 'supportInstanceCtrl'
});
}

将此服务包含在您的 Controller 中,并调用 openPopupModal 方法。例如:

.controller('noResultCtrl', ['$location','$scope','$log','search','$state','modalProvider',function ($location,$scope,$log,search,$state,modalProvider) {
'use strict';
modalProvider.openPopupModal();

关于angularjs - Angular Calling Modal Open 功能从一个 Controller 到另一个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28086854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com