AngularStrap - 模态不隐藏

时间:2015-08-24 09:28:31

标签: angularjs angular-strap

我只使用HTML标签调用模式:

<?php 
if (!empty($_GET['status']) && $_GET['status'] == "login_fail") {
  echo "invalid user";
}
?>

但之后我只能用&#34;关闭&#34;关闭我的模态。按钮,而不是&#34;保存更改&#34;。

这是我的外部模态模板:

<button class="btn btn-xs stop" data-template-url="template/modal.html"
        bs-modal="modal">
</button>

和我的modalController:

<div class="modal" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document" ng-controller="modalController">
    <div class="modal-content">
        <div class="modal-header">
           <h4 class="modal-title" id="task_id"> Task #{{clickedStop}}</h4>
        </div>
        <div class="modal-body">
            <textarea  id="description" class="form-control" placeholder="Description of work on a task"></textarea>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
            <button type="button" class="btn btn-primary" ng-click="saveModal()">Save changes</button>
        </div>
    </div>
</div>

当我尝试使用app.controller('modalController', function($scope, $rootScope){ $scope.saveModal = function (){ $scope.ticket_id = $rootScope.clickedStop; var tickets = localStorage.getItem($scope.ticket_id); var task = JSON.parse(tickets); $scope.description = jQuery("#description").val(); if($scope.description == "" || $scope.description == undefined) { alert("You must enter description!"); return; }; var save = JSON.stringify({ ":task_id":$scope.ticket_id, ":creator":task.creator, ":date_created":task.start, ":owner":task.owner, ":title":task.title, ":description":$scope.description }); jQuery.ajax({ url:"engine/saveActivity.php", method: "POST", data:{data:save}, dataType:'json' }) .success(function (responce){ if (responce === true){ console.log("Activity saved!"); //I wont to close modal here } }).error(function(data){ console.log("Error Activity save!"+ data); }); }; 时,我收到$hide()不是函数的错误。

1 个答案:

答案 0 :(得分:1)

$hide()不起作用,因为您没有加入$modal服务:

app.controller('modalController', function($scope, $rootScope, $modal) {
                                                               ^^^^^^

现在ng-click="$hide()"将按预期工作。正如docs所指出的那样:

  

将bs-modal属性附加到任何元素以激活指令。

     

该模块还公开了一个$ modal服务,可供程序化使用   (在指令/控制器内)

但是你必须包含它才能使用它。