angularjs模态取消不起作用

时间:2016-01-21 15:11:53

标签: 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');
  }; 

1 个答案:

答案 0 :(得分: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');
    };
相关问题