I am stuck thanks to ng-submit not working, it won't run when I click on it

147 Views Asked by At

I am taking an online course, and I am stuck on an assignment. In my assignment, I have a form and a form button that runs code when you click on a button. However, my code does not run at all when I click on the submit button. Here is the nested div of my code where the problem is. I've edited stuff out, and kept all the information pertaining to my problem.

EDIT: I solved it, I found the problem. It started working once I changed ng-submit="contoller1.myFunction" to just ng-submit="myFunction()". It's kinda weird, but it works.

<div ng-controller="Controller as controller1">

        <div class="row row-content">

            <form class="form-horizontal" role="form" novalidate name="myForm"  ng-submit="controller1.myFunction()">

                <div class="form-group">

                    <label class="control-label col-sm-2" for="name">Your Name</label>

                    <div>

                        <input type="text" id="name" name="name"  class="form-control" placeholder="Enter Your Name" required>


                    </div>

                </div>

                <div class="form-group">


                    <label for="commentField" class="col-sm-2 control-label">Your Comments</label>


                    <div>

                        <textarea class="form-control" id="commentField"  name="feedback" rows="12" required></textarea>

                    </div>

                </div>




                        <div class="form-group">

                            <div>

                            <button type="submit" class="btn btn-primary">Submit Comment</button>


                        </div>



                </div>




            </form>

        </div>
     </div>
2

There are 2 best solutions below

3
On

Remove the ng-submit on the form tag and change your button:

<button type="submit" class="btn btn-primary" ng-click="vm.submit()">Submit Comment</button>

You'll also be needing the 'action' attribute on your form. And models on the inputs if you want to do something with the data (save, parse etc).

1
On

Aren't you missing ng-models on your elements? ng-model is the data that gets passed between the client and the server.