2016-01-21 71 views
0

我创建了一个模式上单击添加新按钮,在模式我有保存和关闭按钮,我有功能写我我的控制器关闭点击,以便该模式关闭点击,但我我有这些问题。 代码下面提供angularjs模式取消不起作用

视图代码

<button type="button" class="btn btn-default" ng-click="clickAddComment()">Add new</button> 
<script type="text/ng-template" id="myModalContent.html"> 
       <div class="modal-header"> 
         <h3 class="modal-title">Comments Section</h3> 
       </div>  
        <div class="modal-body"> 
         <div class="form-group"> 
        <form> 
        <label for="text">Name</label><br /> 
        <input type="text class="form-control" id="title" placeholder="Enter Title" /> <br /> 
           <label for="text">Author</label><br /> 
        <input type="text class="form-control" id="title" placeholder="Enter Name" /><br /> 
           <label for="text">Date</label><br /> 
        <input type="date" class="form-control" style="width:155px;" id="currdate" /> <br /> 
           <label for="text">Comments</label><br /> 
        <textarea rows="4" cols="50"></textarea> 

        </form> 
        </div> 
        <div class="modal-footer"> 
         <button class="btn btn-primary" type="button" ng-click="ok()">OK</button> 
         <button class="btn btn-warning" type="button" ng-click="canc()">Cancel</button> 
        </div> 
</script> 

和控制器我有

$scope.clickAddComment = function() { 
     modalInstance = $uibModal.open({ 
      animation: $scope.animationsEnabled, 
      templateUrl: 'myModalContent.html', 
      controller: 'someController' 
     }); 
    } 

$scope.canc = function() { 
    $uibModalInstance.dismiss('canc'); 
    }; 
+0

你能发布plunkr? –

回答

0
just added modalInstance to canc function instead of $uibModalInstance as i am targetting the same modal 
$scope.clickAddComment = function() { 
     modalInstance = $uibModal.open({ 
      animation: $scope.animationsEnabled, 
      templateUrl: 'myModalContent.html', 
      controller: 'someController' 
     }); 
    } 
$scope.canc = function() { 
     modalInstance.dismiss('canc'); 
    };