加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular Calling Modal从一个控制器到另一个控制器

发布时间:2020-12-17 07:08:40 所属栏目:安全 来源:网络整理
导读:我的标题中有一个模态窗口,标题中有一个Click事件链接,用于打开和关闭模态窗口……这样可以正常工作.即 div class="header" ng-controller="headerCtrl"... lia href ng-click="open()"Report an Issue/a/li.../div 然后我的控制器 .controller('headerCtrl'
我的标题中有一个模态窗口,标题中有一个Click事件链接,用于打开和关闭模态窗口……这样可以正常工作.即

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

然后我的控制器

.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','$modalInstance','$state',$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;
    };
  }])

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

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

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

解决方法

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

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

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

.controller('noResultCtrl','modalProvider',modalProvider) {
    'use strict';
modalProvider.openPopupModal();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读