0

I'm trying to get the input values for a form I'm submitting and the data angular-ui is binding to the form is not what I expected. An example form:

<form name="myform" method="post" data-ng-submit="submit()">
    <input type="text" name="myform.firstname" />
    <input type="submit" value="submit" />
</form>

and in submit() I am just doing console.log($scope.myform)

I was expecting: { firstname: "sample" } but I am instead getting:

{ $error: Object, $$success: Object, $pending: undefined, $name: "myform", $dirty: false, $pristine: true, $valid: true, $invalid: false, $submitted: true, $$parentForm: Object, 10 more… }

The input key and its value don't seem to be in here and even if I use a model, angular-ui is overriding the object on submit.

1

1 Answer 1

-1

Notice name and ng-model attributes on input field. ng-model is important to do the data binding between angular scope and html elements.

<form name="myform" method="post" data-ng-submit="submit()">
    <input type="text" name="firstname" ng-model="myform.firstname" />
    <input type="submit" value="submit" />
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

This is an angular-ui related issue, this will add a firstname object to myform however the firstname object looks similar to the one I added in my question. I just want to get the value from the input firstname in the myform object..

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.