Monday, June 16, 2014

How to fix AngularJS ng-click causing the page refresh in Button Click

I create a Demo App with AngularJS in Sharepoint 2013 Environment.

the Demo App works well with Both FireFox and IE Browser. However the app always refresh and reload the content when i click on any button in Safari.

here is my Code

<div ng-controller="AddContactControl">
                    <button ng-click="showAddModal(contact)">Add Contact</button>
 </div>


the root cause of issue is that the button had been automatically assigned with type "submit" if type is not assigned at design time. as a result, the click will trigger the post back.

the fix is quiet simple
<div ng-controller="AddContactControl">
                    <button ng-click="showAddModal(contact)" type="button">Add Contact</button>
  </div>

another fix is change to button to a anchor

<div ng-controller="AddContactControl">
                    <a ng-click="showAddModal(contact)" >Add Contact</a>
 </div>

9 comments:

  1. From my point Angularjs Training In Hyderabad has only difference. It is learning at Hyderabad helped me in many ways and learning from the informative weblogs like this helped me to connect to more examples, realtime scenarios and case-studies. Thanks a lot.

    ReplyDelete
  2. Thanks. Worked like a charm

    ReplyDelete
  3. thank very much, this solved my problem

    ReplyDelete
  4. Excellent blog with lots of information, keep sharing. I am waiting for your more posts like this or related to any other informative topic.Amazing web journal I visit this blog it's extremely marvelous.
    Salesforce Training in Chennai

    Salesforce Online Training in Chennai

    Salesforce Training in Bangalore

    Salesforce Training in Hyderabad

    Salesforce training in ameerpet

    Salesforce Training in Pune

    Salesforce Online Training

    Salesforce Training

    ReplyDelete
  5. It is my first visit to your blog, and I am very impressed with the articles that you serve. Give adequate knowledge for me. Thank you for sharing useful material. I will be back for the more great post. PS5Home

    ReplyDelete
  6. This post is so interactive and informative. keep update more information...
    devops training institutes in hyderabad

    ReplyDelete
  7. Hey, thanks for the blog article.Really thank you! Great.click here for more information

    ReplyDelete