只是Angular JS的初学者。在模态窗口场景中苦苦挣扎。以下是我的应用程序中的一个简单场景:
具有“添加新”按钮的登陆主页,单击“添加新”按钮将打开一个模式窗口,该窗口具有冗长的形式。以下是我面临的问题/问题:
目标网页模板(home.html)
{..............
..............
<div class="pull-right">
<button type="button" class="btn btn-primary btn-with-text" ng-click="addModalOpen = true">
<span class="glyphicon glyphicon-plus"></span> Add New Item
</button>
</div>
............
..........
<form name="createRIForm" class="form-horizontal col-sm-6">
<div ng-controller="AddCtrl" class="modal fade" ng-include="'createNewRI.html'" ng-class="{'in' : $parent.addModalOpen}">
</div></form>
.......
....... End of the main landing page i.e., home.html }
模态窗口模板html(createNewRI.html)
...............
...........
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" ng-click="$parent.addModalOpen = false">× </button>
<h4 class="modal-title" id="myModalLabel">Create New Item</h4>
</div>
<div class="modal-body">
...modal body contains around 25 fields ....
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-primary">Delete</button>
</div>
</div>
</div>
}
任何帮助都会立即帮助我,因为我对此非常不满意。根据我上面的代码片段,有人可以帮我一些代码片段吗?
答案 0 :(得分:0)
您无需费心存储模态的当前状态,只需将其打开并关闭即可。这是我的尝试(我已多次使用此方法,但此特定代码未经测试):
HTML ,更改为点击按钮时执行showModal
,并从表单中删除了ng-class
:
<div class="pull-right">
<button type="button" class="btn btn-primary btn-with-text" ng-click="showModal()">
<span class="glyphicon glyphicon-plus"></span> Add New Item
</button>
</div>
..........
<form name="createRIForm" class="form-horizontal col-sm-6">
<div ng-controller="AddCtrl" class="modal fade" ng-include="'createNewRI.html'">
</div></form>
<强>角强>:
// In the controller
$scope.showModal = function() {
$(".modal").modal("show");
}
模态,更改为仅使用data-dismiss
:
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4 class="modal-title" id="myModalLabel">Create New Item</h4>
</div>
<!-- DELETED FOR BREVITY -->
</div>