【发布时间】:2015-11-17 16:04:12
【问题描述】:
我只用 HTML 标记调用了模态:
<button class="btn btn-xs stop" data-template-url="template/modal.html"
bs-modal="modal">
</button>
但在那之后我只能用“关闭”按钮关闭我的模式,而不是“保存更改”。
这是我的外部模态模板:
<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() 时,我收到$hide 不是函数的错误。
【问题讨论】:
-
您对您的模态有参考吗?你如何以及在哪里打开它?你不能只调用 $hide 因为那不是一个函数,所以你可能正在寻找 $('#your-modal').hide()
-
我在单击按钮时打开模式。如您所见,标签末尾有
bs-modal="modal"。我试过$('#modal').hide(),但没有 -
我认为stackoverflow.com/a/25446099/4571812 可能会对您有所帮助
-
我使用的不是 Angular UI,而是 AngularStrap modal