When I click the submit button in a form it is adding a ? right before the # so /app/#/pageName changes into /app/?#/pageName. Is this normal behavior? Code is just basic stuff.
angular.module('myApp', [])
.controller('MyCtrl', function ($scope) {
$scope.submit = function() {
};
});
<form ng-controller="MyCtrl" ng-submit="submit()">
<button>Submit</button>
</form>
I finally found the answer thanks to Angular JS does not allow preventDefault or return false to work on form submission.
in my ng-submit
I had to add $event
as parameter which passed the event to my submit function and I was then able to do event.preventDefault()
to prevent the route from changing. Not sure if this is a bug in angular or if it's intended behaviour but hopefully this will help someone else.
So here is the fixed code:
angular.module('myApp', [])
.controller('MyCtrl', function ($scope) {
$scope.submit = function(event) {
event.preventDefault();
};
});
<form ng-controller="MyCtrl" ng-submit="submit($event)">
<button>Submit</button>
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With