0

I was trying to create one simple lightning component which have one button and on click of that button, i want to display alert message which is in controller. Its showing error as unknown method:handleClick. Can you please help me with this? Also if you share links for examples to create lightning components, it will really helpful for me.

component:

<aura:component> 
    <p>Hello lightning</p> 
    <ui:button aura:id="button" label="Click me" press="{!c.getInput}"/>   
</aura:component> 

controller:

({ 
    getInput : function(cmp, event) { 
       alert("hello there!"); 
    }, 
})   

app:

<aura:application >
<c:helloWorld /></aura:application>                                                                                                      
  • Please share your code so that we can help you out. – Praveen Dec 16 '16 at 7:32
1

I have tested with the following code and its working, following is the screenshot - enter image description here

App Code -

<aura:application extends="force:slds" implements="force:appHostable">
    <c:TestClick />
</aura:application>

Component -

<aura:component> 
    <p>Hello lightning</p> 
    <ui:button aura:id="button" label="Click me" press="{!c.getInput}"/>   
</aura:component> 

Controller JS -

({ 
    getInput : function(cmp, event) { 
      alert("hello there!"); 
    }
}) 
  • I tried above code but still giving same error. I called getInput method on press and the same method i have in controller. – Sofiya Dec 16 '16 at 9:49
  • post your entire app, component, js controller code – Nirmallya Ghosh Dec 16 '16 at 9:56
  • edited the question. – Sofiya Dec 16 '16 at 10:00
  • @NirmallyaGhosh Please edit your answer rather than adding a new answer. So just Delete of one of your answer – Praveen Dec 16 '16 at 10:03
  • @Sofiya I have attached the success screenshot and all code sample, if works please mark it as answer – Nirmallya Ghosh Dec 16 '16 at 10:14
0

Component

<aura:component >
    <ui:button label="clickme" press="{!c.getAlert}"/>
    <input type="button" value="clickme"
           onclick="{!c.getAlert}"/>
</aura:component>

Controller

({
    getAlert : function(cmp, evt) {
    alert("BUTTON PRESSED");

    }
})
  • Its giving error as- This page has an error. You might just need to refresh it. Assertion Failed!: Unknown controller action 'getAlert' : undefined Failing descriptor: {ui$button$controller$press} . Am i missing something? – Sofiya Dec 16 '16 at 7:48

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.