I am trying to call my controller after a button click, but it's not being called. What is the problem?

After I click on 'Add Contact' it's not calling the AddContact Method. I don't understand why it's not calling AddContact

 <div id="conshow">
                                <div class="tab-pane" id="contact" >
                                    <table class="table table-bordered">

                                                <th>Contact Type</th>

                                            <aura:iteration items="{!v.condata}" var="condetails">  

                                                    <a data-record="{!condetails.Id}" onclick="{!c.EditContact}">Edit</a>

                                                    <!--<a class="btn  btn-primary"  press= "{!c.EditContact}" >Edit</a> -->

<a class="btn btn-primary btn-block mt10"  onclick="{!c.AddContData}">    Add New Contact</a>

AddContData:function (component,event,Helper)
 // $('#AddContacts').modal('show');
    $(document).ready(function() { 


   // alert();

 EditContact:function (component,event,Helper)

As you are not using an aura ui element you need to use the normal 'onclick' property instead of 'press'(press is ui:.. tag related event). so change the mark up to:

<a class="btn btn-danger" data-backdrop="false"  onclick="{!c.AddContacts}"> Add New Contact</a>
  • thanks gopal sir I already tried it but it not work – pankaj singh Jun 22 '16 at 17:46
  • Try removing data-backdrop="false" in anchor tag and check it. – Bala Jun 22 '16 at 19:43
  • its not work sir.. – pankaj singh Jun 23 '16 at 4:09
  • have you tried removing the 'span' inside the anchor tag – Gopal Rao Jun 23 '16 at 7:06

I Tried your same code and its working fine for me. try inserting alert in the controller method.

     AddContData : function(component, event) {
                       alert('Add Contact Data');
  • sir its work out side div but in div not work – pankaj singh Jun 23 '16 at 11:00
  • Could you please post the code after removing confidential data if any ? – Junaid P Khader Jun 23 '16 at 11:44
  • Junaid P Khadar sir i edited code plz check it – pankaj singh Jun 23 '16 at 12:11
  • I saw the code. But I didnt find any mistake in that. Have you added static resources to the component ? – Junaid P Khader Jun 27 '16 at 4:14
  • yes sir i added static resource – pankaj singh Jun 27 '16 at 4:46

I just tried out your code and the click is working. Maybe something else inside your "AddContData:function" is going wrong. Include a console or alert inside the function and you can make sure that the particular function is being fired.

Try this:-

<div class="conshow"> 
   <span class="glyphicon glyphicon-camera" aria-hidden="true"></span>
   <button onclick="{!c.AddContData}" >Add New</button>
  • yes arvind sir, its work out side div but i try it in div its not work <div id="conshow"> <div class="tab-pane" id="contact" > //Above code here </div></div> – pankaj singh Jun 23 '16 at 7:33
  • You're trying to call a function on a button click, right? Then do it like this:- <div class="conshow"><span class="glyphicon glyphicon-camera" aria-hidden="true"></span><button onclick="{!c.AddContData}" >Add New</button> </div> Also, I would suggest you to use meaningful names for your id/class. – SE_User Jun 23 '16 at 8:57
  • I tried it but no result – pankaj singh Jun 23 '16 at 10:36
  • Hi Pankaj, the above code did work for me. There might be some other issue in your code. Can you please share screenshots of your code (comprising this part mainly)? Not just controller, the components, as well as the controller code. – SE_User Jun 23 '16 at 11:41
  • Hii Arvind , I edited code with div plz check it – pankaj singh Jun 23 '16 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.