I have the following template (it's larger, here's only a part of it):

  <div id="prefCenter_Interest" class="prefCenter_Block">
    <div if:true={isRoleSelected}>
         <template for:each={objInfo.todoList} for:item='todoListItem'>
                      checked={todoListItem.value} >
           <button type="button" onclick={handleName}>SAVE MY NAME</button>

And in my JavaScript file it says

export default class ToDoList extends LightningElement {
    isNameSelected = false;

    handleRole(event) {
        this.isRoleSelected = true;
    handleName(event) {
        this.isNameSelected = true;

I would expect the first template böock to be visible as soon as I click a button with the handler handleRole.

But instead it displays an error: Uncaught TypeError: Cannot read property 'apply' of undefined throws

What am I missing?

1 Answer 1


There is no button with handler handleRole in the code you provided, so it's not possible to be sure, but "TypeError: Cannot read property 'apply' of undefined" is thrown when a button is clicked with a handler name that does not exist in the javascript class. You probably have a typo in your html template. Keep in mind that variable names in javascript and lwc templates are case sensitive.

  • Seems to me that this was a typical beginners mistake... shame Yes, I am a beginner in LWC developing and I was under pressure yesterday. But I definitly could have seen this. Thanks a lot, it works now!
    – JonSnow
    Jan 25, 2022 at 7:23

You must log in to answer this question.

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