I have a form in Angular with two button labels. A button submits the form on ng-click
. The other button is purely for navigation using ng-click
. However, when this second button is clicked, AngularJS causes the page to refresh, triggering a 404 error. I set a breakpoint in the function and it triggers my function. If I do any of the following, it stops:
ng-click
, the button does not cause the page to refresh.
) and add href=""
it does not cause a refresh . The latter seems to be the easiest solution, but why does AngularJS run any code after my function that causes the page to reload? Looks like a bug.
This is the form:
This is the controller method:
$scope.showChangePassword = function() { $scope.selectedLink = "changePassword"; };
You can try blocking the default handler:
html:
js:
If you look at theW3C spec, it seems like the obvious thing to try is to mark
type='button'
on the button element that you don't want submitted.Special attention should be paid to the location it says