Angular Calling Modal打开从一个控制器到另一个控制器的功能

Ste*_*ieB 3 modal-dialog twitter-bootstrap angularjs

我的标题中有一个模态窗口,标题中有一个Click事件链接,用于打开和关闭模态窗口......这样可以正常工作.即

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

然后我的控制器

 .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;
    };
  }])
Run Code Online (Sandbox Code Playgroud)

问题现在出现在我的一个主要内容视图中,我现在还有一个链接,下面点击此处点击支持.我想再次打开相同的模态窗口.所以我这样做了

  .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'
      });
    };
  }])
Run Code Online (Sandbox Code Playgroud)

并且它有效但是有一个更好的方法,而不是必须将相同的逻辑放在我想在标题中调用相同的模态窗口的每个控制器中吗?

Ved*_*Ved 7

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

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

在控制器中包含此服务,并调用openPopupModal方法.例如:

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