0

Before I continue to my question, I know ho to get form data inside AngularJs using ngModel, but it's giving some problems since everytime users interact with the form it will run the digest cycle, which can cause some performance problems in some areas of my application.

I know I can have "some" control over this by using ngModelOption, but it's not something simple to use, since I would need to apply it for each ngModel inside the form. At least I don't know another way to go over this situation.


Basically what I need is to have a simple form, doesn't need to update anything immediately (think about a login form, user registration, for example, where we just need to collect the data and send to the database).

As simple as this:

<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>

But without all the events used inside AngularJs, which will fire the digestCycle, go over other areas, etc..

Note: I can just use AngularJs (or pure JS) to do this.

1
  • then how will you validate your form? try writing jQuery for those! Commented Dec 9, 2016 at 2:05

1 Answer 1

1

If you are allowed to use jQuery (not just jqLite). Then you can do this to serialize a form

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>

script

angular.module('myApp', []).controller('MyCtrl', function($scope) {
    $scope.LogIn = function()
    console.log(angular.element('#loginForm').serialize());//Check
});
Sign up to request clarification or add additional context in comments.

2 Comments

isn't it possible using just jqLite?
I don't think .serialize() is available in the lite version.. but worth a shot..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.