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>                                                                                                      
1
  • Please share your code so that we can help you out.
    – Praveen
    Commented Dec 16, 2016 at 7:32

2 Answers 2

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!"); 
    }
}) 
7
  • I tried above code but still giving same error. I called getInput method on press and the same method i have in controller.
    – Sofiya
    Commented Dec 16, 2016 at 9:49
  • post your entire app, component, js controller code Commented Dec 16, 2016 at 9:56
  • edited the question.
    – Sofiya
    Commented Dec 16, 2016 at 10:00
  • @NirmallyaGhosh Please edit your answer rather than adding a new answer. So just Delete of one of your answer
    – Praveen
    Commented Dec 16, 2016 at 10:03
  • @Sofiya I have attached the success screenshot and all code sample, if works please mark it as answer Commented Dec 16, 2016 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");

    }
})
1
  • 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
    Commented Dec 16, 2016 at 7:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .