在继续我的问题之前,我知道如何使用 ngModel
在 AngularJs
中获取表单数据,但它会带来一些问题,因为每次用户与表单交互时,它都会运行摘要循环,这可能会在我的应用程序的某些区域导致一些性能问题。
我知道我可以通过使用ngModelOption
对此进行“一些”控制,但它使用起来并不简单,因为我需要将它应用于每个ngModel
表格内。至少我不知道还有什么方法可以解决这种情况。
基本上我需要的是一个简单的表单,不需要立即更新任何内容(例如,考虑登录表单、用户注册,我们只需要收集数据并将其发送到数据库)。
就这么简单:
<form name="loginForm" novalidate ng-submit="loginForm.$valid && vm.login()">
<input type="email" name="email" placeholder="E-mail" required />
<input type="password" name="password" placeholder="Password" required />
<button>Login</button>
</form>
但是如果没有 AngularJs 内部使用的所有事件,这些事件将触发digestCycle、遍历其他区域等等......
Note: I can just use AngularJs (or pure JS) to do this.
最佳答案
如果您被允许使用jQuery (not just jqLite) 。然后你可以这样做来序列化表单
html
<div ng-controller="MyCtrl">
<form id="loginForm" name="loginForm" novalidate ng-submit="loginForm.$valid && vm.login()">
<input type="email" name="email" placeholder="E-mail" required />
<input type="password" name="password" placeholder="Password" required />
<button type='button' ng-click="LogIn()">Login</button>
</form>
</div>
脚本
angular.module('myApp', []).controller('MyCtrl', function($scope) {
$scope.LogIn = function()
console.log(angular.element('#loginForm').serialize());//Check
});
关于javascript - AngularJs 不使用 ngModel 序列化表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41051031/