我在AngularJS中有一个表单视图,我使用Angular-ui中的一个模态来显示我的表单.功能方面,一切都很好,但是,当我关闭表单时,如果表单无效,则显示验证弹出窗口.
这就是它的样子:
当表单打开时,弹出窗口根本不显示,但只有当我单击取消并且它开始消失时才会显示.
HMTL:
<form name='newGroupForm'> <div class="modal-body"> <label for="groupName">Group Name: <input id="groupName" type="text" ng-model='newGroup.name' required> </label> <br/> <label for="groupDesc">Group Description: <input id="groupDesc" type="text" ng-model='newGroup.desc'> </label> <br/> <label for="groupOwner">Group Name: <select id="groupOwner" type="text" ></select> </label> </div> <div class="modal-footer"> <button class="btn btn-warning" ng-click="cancel()">Cancel</button> <button class="btn btn-primary" type="button" ng-click="submit()" ng-disabled="newGroupForm.$invalid">Create</button> </div> </form>
模态控制器:
spApp.controller('newGroupCtrl',function newGroupCtrl($scope,$modalinstance,groupService){ $scope.newGroup = { name:null,desc: null }; $scope.submit = function(){ $modalinstance.close($scope.newGroup); } $scope.cancel = function (){ $modalinstance.dismiss('Cancelled group creation'); }; } );