Submit button not working with Form

1.5k views Asked by At

I have an issue with a form in angular where the submit button in the form just causes the form to do the standard submit instead of running what is defined in ng-click. It is as if what is ng-click isn't even being called.

Here is the html and js

<form ng-controller="formController" name="create_champion_form">
    {{ create_champion_form.as_p }}
    <button ng-click="submit()">Hello</button> 
</form>

 urm.controller('formController', function($scope) {
    $scope.submit = function() {
        alert("Working");
    };
});

Any ideas on this issue would be great as I have been trying for a few days and nothing I have tried has worked.

2

There are 2 answers

0
NItesh Shrestha On BEST ANSWER

I think you forgot to include 'ng-app' in your app. I have tried this and its working fine. working code is:

Html:

<body ng-app='app'>
  <form ng-controller="formController" name="create_champion_form">
    {{ create_champion_form.as_p }}
    <button ng-click="submit()">Hello</button> 
</form>
</body>

Javascript:

var urm=angular.module('app',[]);
urm.controller('formController',function($scope){
  $scope.submit = function() {
        alert("Working");
    };
});
0
Shubham Nigam On

I think you didnt use ng-app or you are getting error because any undefined thing or anyother reason elsewise it is working fine simple fiddle for solution:-
https://jsfiddle.net/vh3n1dp2/2/