Reputation: 459
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.
Upvotes: 1
Views: 1495
Reputation: 76
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");
};
});
Upvotes: 1
Reputation: 3944
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/
Upvotes: 1