2017-10-17 13 views
0

このPLUNKには、角度UIモーダルと閉じるボタンがあります。 Modalインスタンスに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") 
}); 
関連する問題