Javascript 单击按钮关闭模态对话框并刷新表angularjs
我正在使用模态对话框添加和更新记录。单击Javascript 单击按钮关闭模态对话框并刷新表angularjs,javascript,angularjs,twitter-bootstrap,bootstrap-modal,mean,Javascript,Angularjs,Twitter Bootstrap,Bootstrap Modal,Mean,我正在使用模态对话框添加和更新记录。单击添加或更新按钮,然后刷新我的表格后,我想关闭模式对话框 以下是我的查看代码: <form name="clientForm" ng-submit="check(cid)" ng-controller="ClientsController"> <div class="form-group"> <label for="name">Name</label>
添加
或更新
按钮,然后刷新我的表格后,我想关闭模式对话框
以下是我的查看代码:
<form name="clientForm" ng-submit="check(cid)" ng-controller="ClientsController">
<div class="form-group">
<label for="name">Name</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-hand-right"></i></span>
<input type="text" class="form-control" id="title" placeholder="Enter Name" ng-model="client.name">
</div>
</div>
<div class="form-group">
<label for="email">Email</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="text" class="form-control" id="title" placeholder="Enter Email" ng-model="client.email">
</div>
</div>
<div class="form-group">
<label for="phone">Phone</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="glyphicon glyphicon-earphone"></i></span>
<input type="text" class="form-control" id="title" placeholder="Enter Phone" ng-model="client.phone">
</div>
</div>
<div class="well well-lg text-center bg-gray">
<button class="btn btn-success" ng-if="cid">Save Client</button>
<button class="btn btn-danger" ng-if="cid" title="Delete" confirmed-click="remove(client._id)" ng-confirm-click="Are you sure you want to remove?">Delete</button>
<button type="button" class="btn btn-warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn btn-success" ng-if="!cid">Add Client</button>
</div>
</form>
这是我的模态指令:
DemoApp.directive('modal', function () {
return {
template: '<div class="modal fade">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header bg-primary">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
'<h4 class="modal-title">{{ title }}</h4>' +
'</div>' +
'<div class="modal-body" ng-transclude></div>' +
'</div>' +
'</div>' +
'</div>',
restrict: 'E',
transclude: true,
replace: true,
scope: true,
link: function postLink(scope, element, attrs) {
scope.title = attrs.title;
scope.$watch(attrs.visible, function (value) {
if (value == true)
$(element).modal('show');
else
$(element).modal('hide');
});
$(element).on('shown.bs.modal', function () {
scope.$apply(function () {
scope.$parent[attrs.visible] = true;
});
});
$(element).on('hidden.bs.modal', function () {
scope.$apply(function () {
scope.$parent[attrs.visible] = false;
});
});
}
};
});
DemoApp.directive('modal',function(){
返回{
模板:“”+
'' +
'' +
'' +
“×;”+
“{{title}}”+
'' +
'' +
'' +
'' +
'',
限制:'E',
是的,
替换:正确,
范围:正确,
链接:函数postLink(范围、元素、属性){
scope.title=attrs.title;
范围$watch(属性可见,函数(值){
如果(值==true)
$(元素).modal('show');
其他的
$(元素).modal('hide');
});
$(元素).on('show.bs.modal',函数(){
作用域:$apply(函数(){
scope.$parent[attrs.visible]=true;
});
});
$(元素).on('hidden.bs.modal',函数(){
作用域:$apply(函数(){
scope.$parent[attrs.visible]=false;
});
});
}
};
});
布局:已加载脚本
<script src="js/vendor/angular/angular.js"></script>
<script src="js/vendor/angular/angular-route.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/ClientsController.js"></script>
<script src="js/directives/modal.js"></script>
<script src="js/directives/pageSelect.directive.js"></script>
<script src="js/directives/confirm.js"></script>
<script src="js/services/flashService.js"></script>
<script src="vendor/ie10-viewport-bug-workaround.js"></script>
<script src="js/module/smart-table.debug.js"></script>
<script src="js/vendor/angular-smart-table/dist/smart-table.min.js"></script>
如您所见,我正在调用$scope.closemodal()
关闭模式对话框,并刷新()
在从服务器获得响应后刷新表,但它不工作
任何帮助都将不胜感激。您能否与加载的所有脚本共享完整的index.html,以便我能够重现您的问题。@ygabel:Updated。请检查修改后的帖子。您应该真正更新showModal和showModel/hideModel命名,以修复混淆。不要使用!值,因为这可能会导致问题。简单地使用false或true。遗憾的是,我还没有看到问题所在。我甚至不明白为什么它一开始就起作用了:/@ygabel:@sciencefyll:我试过这个
angular.element('.modal').modal('hide')
及其关闭模式但不更新表您是否已验证添加/更新的记录是否已成功进入数据存储?
<script src="js/vendor/angular/angular.js"></script>
<script src="js/vendor/angular/angular-route.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/ClientsController.js"></script>
<script src="js/directives/modal.js"></script>
<script src="js/directives/pageSelect.directive.js"></script>
<script src="js/directives/confirm.js"></script>
<script src="js/services/flashService.js"></script>
<script src="vendor/ie10-viewport-bug-workaround.js"></script>
<script src="js/module/smart-table.debug.js"></script>
<script src="js/vendor/angular-smart-table/dist/smart-table.min.js"></script>