Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form is undefined in scope in Angular 1.3

Tags:

angularjs

I don't if this is something I did, but once I upgraded to Angular 1.3, the form is no longer defined in my scope. My HTML is

<div some-dir>

    <form name="myForm">
    <!-- Form stuff here -->
    <button ng-click="submit();">
    </form>

</div>

The submit function is

scope.submit = function() {
    console.log(scope.myForm);
}

And this returns undefined. I have no ng-if or ng-repeat anywhere. There is only one directive and one scope in this specific directive. Again, this was all working until I upgraded to Angular 1.3

like image 237
Kousha Avatar asked Mar 02 '26 18:03

Kousha


1 Answers

The problem can be solved by scoping form data into some scope object:

  <form name="myForms.firstForm">
    <!-- Form stuff here -->
    <button ng-click="submit();">
  </form>

And than:

scope.myForms = {};
scope.submit = function() {
    console.log(scope.myForms.firstForm);
}

Some more info in this comment.

like image 193
Sergey Narozhnyy Avatar answered Mar 06 '26 02:03

Sergey Narozhnyy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!