Why is My AngularJS Button Click Refreshing the Page?
Barbara Streisand
Release: 2024-11-21 08:42:09
Original
674 people have browsed it
AngularJS Button Click Causing Page Refresh
This issue revolves around the default behavior of
In the provided AngularJS form, the with ng-click="showChangePassword()" doesn't explicitly define type. As a result, AngularJS interprets it as a submit button and initiates a form submission, leading to the page refresh.
解决方案
The W3C specification suggests that to prevent form submission, elements should have their type attribute set to 'button'. This signal to the browser that the button should not trigger a form submission.
Modify the causing the page refresh as follows:
By setting type="button", we explicitly instruct the browser that this particular should not submit the form, preventing the unwanted page refresh when clicked.
The above is the detailed content of Why is My AngularJS Button Click Refreshing the Page?. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn