2014-02-11 2 views
2

글로벌 네임 스페이스를 폴링하지 않고 컨트롤러 (& 다른 파일)를 트리거하고있는 상태로 내 Angular Ui Modal 컨트롤러/개체를 선언하고 싶습니다.컨트롤러 외부에서 각도 UI 모달을 선언하는 방법?

이것이 가능합니까? 모달 컨트롤러를 선언 할 수 있습니까? 은 일반 컨트롤러와 같고 어떻게 든 (내 트리거 컨트롤러에서) 매개 변수를 전달합니까?

내가 현재 가지고 : (쿨하지 않은)

(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) { 
    } 
}); 

답변

3

여기 예를 글로벌하지 않은 : 예는 더 복잡하지만 이것은 좋은 대답은 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; 
      }); 
     } 
     } 
    }); 
    }; 

}); 
+0

약속을 가지고 일할 때 필요 이상으로. $ timeout 그 자체는 약속에 기반을두고 있기 때문에 예제는 http://plnkr.co/edit/yaQpW9uyZHmo8BdIaLxt?p=preview –

+1

으로 축소 될 수 있습니다. 모달 컨트롤러를 선언 할 때 별도의 파일로 선언 할 수 없습니다 트리거 컨트롤러 ?? – Baconbeastnz

+1

@Baconbeastnz 다음과 같이 할 수도 있습니다. http : //plnkr.co/edit/lI2Z8FEjZIdx6lelnqhx? p = preview – igorzg

관련 문제