2017-10-17 10 views
0

PLUNK에서 저는 각도 UI 모달과 버튼을 닫습니다. 모달 인스턴스에 close 메서드가 없으므로 단추가 작동하지 않습니다.각도 UI 모달에서 닫기 버튼이 작동하지 않습니다.

rendered 문을 제거하면 단추가 작동합니다. rendered과 함께 작동하지 않는 이유는 무엇입니까?

이 작동하지 않습니다

var app = angular.module('app', ['ui.bootstrap']); 

app.controller('myCtl', function($scope,$uibModal) { 

     $scope.openModal = function() { 
      $scope.modalInstance = $uibModal.open({ 
       templateUrl: 'myModalContent.html', 
       scope: $scope 
      }).rendered.then(function() { 
       alert("modal rendered") 
      }); 
     }; 

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

}) 

이합니까 일 (PLUNK 참조)

var app = angular.module('app', ['ui.bootstrap']); 

app.controller('myCtl', function($scope,$uibModal) { 

     $scope.openModal = function() { 
      $scope.modalInstance = $uibModal.open({ 
       templateUrl: 'myModalContent.html', 
       scope: $scope 
      }); 
     }; 

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

}) 

답변

1

을 첫 번째 경우에, 당신은 $scopemodalInstancerendered 약속이 아닌 인스턴스를 할당한다. 다음과 같이하면 (Plunk) 작동합니다 :

$scope.modalInstance = $uibModal.open({ 
    templateUrl: 'myModalContent.html', 
    scope: $scope 
}); 
$scope.modalInstance.rendered.then(function() { 
    alert("modal rendered") 
});