我有一个表格,里面有一些字段。当用户填充所有字段并提交表单时,我强迫用户在表单提交之前注册或登录(在模式窗口中)。
也就是说,当用户尝试提交表单时,我首先用登录表单打开一个模式窗口(用户可以切换注册/登录表单)。在用户完成登录/注册表单并提交之后,我使用ajax发送所有数据,在获得成功状态后,我使用jQuery的$("formID").submit()事件提交前面的表单。
现在,当我从jQuery迁移到angularJS时,我试图找到一种解决方案,使用angularJS完成用户注册/登录部分,使用angularJS的$http服务完成用户注册/登录部分,但未能提交之前的表单数据。
这种事情有什么angularJS解决方案吗?是否可以提交带有ID的表单或类似的内容?
发布于 2013-09-08 06:03:06
我相信我已经做了你要求的一切。现场演示(点击)。
<div ng-show="successMessage">
<p>{{successMessage}}</p>
<h6>Form data sent:</h6>
<p ng-repeat="(k,v) in form track by k">{{k}}: {{v}}</p>
</div>
<form ng-submit="mySubmit()" ng-hide="modalOpen||successMessage">
<input ng-model="form.name" placeholder="Name">
<input ng-model="form.phone" placeholder="Phone Number">
<input type="submit">
</form>
<div ng-show="modalOpen">
<h6>This would be your modal.</h6>
<p>Login to submit form!<p>
<button ng-click="login()">Login</button>
</div>
var app = angular.module('myApp', []);
app.controller('appCtrl', function($scope) {
$scope.form = {
name: '',
phone: ''
};
$scope.modalOpen = false;
$scope.mySubmit = function() {
$scope.modalOpen = true;
};
$scope.login = function() {
$scope.loggedIn = true; //should come from a service and use promise, send form after promise resolves using .then()
//dataService.sendForm() or however you want to submit the form. the same principle applies about using a promise and .then() function to set the successMessage and close modal.
$scope.successMessage = 'Form is submitted!';
$scope.modalOpen = false;
};
});发布于 2013-09-05 06:20:38
检查这个http://docs.angularjs.org/api/ng.directive:ngSubmit
<form ng-submit="{expression}">
...
</form>https://stackoverflow.com/questions/18628257
复制相似问题