简体   繁体   English

如何在控制器外部声明Angular UI Modal?

[英]How to declare Angular UI Modal outside of controller?

I'd like to have my Angular Ui Modal controller/object declared outside it's triggering controller (& in another file), without polutting the global namespace. 我想让我的Angular Ui Modal控制器/对象在其触发控制器(&在另一个文件中)之外声明,而不破坏全局名称空间。

Is this possible? 这可能吗? Is it possible to declare the modal controller like a regular controller and somehow pass parameters in (from my trigger controller)? 是否可以像常规控制器一样声明模态控制器,并以某种方式(从我的触发器控制器)传入参数?

I currently have: (which ain't cool) 我目前有:(这不酷)

(function () {
    TriggeringCtrl.$inject = ['$scope', 'htmlClient', 'apiCall', '$timeout', '$modal', 'utility'];
    function TriggeringCtrl($scope, htmlClient, apiCall, $timeout, $modal, utility) {

   };
  app.controller('TriggeringCtrl', TriggeringCtrl);
  var ModalCtrl = function ($scope, $modalInstance, node, apiCall, utility) {
  }
});

You have example here which is not global: http://plnkr.co/edit/fCfvcnwP9JSHbX5L2Vuu?p=preview 您在这里有一个不全局的示例: http : //plnkr.co/edit/fCfvcnwP9JSHbX5L2Vuu?p=preview

var app = angular.module('plunker', ['ui.bootstrap']);
app.controller('ModalDemoCtrl', function ($scope, $modal, $q, $timeout) {


  $scope.open = function () {
    var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: function ($scope, $modalInstance, items) {

        $scope.items = items;


        $scope.ok = function () {
          $modalInstance.close('item');
        };

        $scope.cancel = function () {
          $modalInstance.dismiss('cancel');
        };
      },
      resolve: {
        items: function () {
          var p = $q.defer(); /// simulate data
          $timeout(function(){
            p.resolve(['item1', 'item2', 'item3']);
          });
          return p.promise.then(function(data){
            return data;
          });
        }
      }
    });
  };

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM