0

my set params is null for some reason. But the variables i'm passing in do have values. I have a console.log before I set params to check before the parameters are set to their values.

Can anyone spot something wrong in my code?`

onDrop: function(component, event, helper)
{
    event.preventDefault();

    var index = component.get('v.index');
    var seatNumber = component.get('v.seatNumber');
    console.log("Target Item Index:",index,"\nTarget Item Seat:",seatNumber); //These work, and have values.

    var cardSwapEvent = component.getEvent('CardOnCardSwap');
    cardSwapEvent.setParams({'seatNumber': seatNumber, index: index}); //This complains "Cannot read property 'setParams' of null"
    cardSwapEvent.fire();

    console.log("CardonCard");
}`

Console output:

Moved Item index: 0 Moved Item Seat: 1 Card.js:26 Target Item Index: 1 Target Item Seat: 2

Error message:

This page has an error. You might just need to refresh it. Action failed: c:Card$controller$onDrop [Cannot read property 'setParams' of null] Failing descriptor: {c:Card$controller$onDrop}

  • index: index ? => 'index' : index (quick observation) – glls Oct 10 '18 at 14:19
  • I've changed that typo, but I still have the same error message after refreshing preventing my event from firing. – Alexander Atkinsoon Oct 10 '18 at 14:21
  • 2
    Can you also include your aura:registerEvent line from .cmp? – Lightning Evangelist Oct 10 '18 at 14:22
  • <!-- Custom Events --> <aura:registerEvent name="cardSwapRegister" type="c:CardSwap"/> – Alexander Atkinsoon Oct 10 '18 at 14:22
  • 5
    The name attribute while registering and handling a component event should be exactly the same. Seems you declared the event name in your registering component as cardSwapRegister and then in handler you have it as cardSwapped, that will not work. Also can you please add the snippet from the comments to your question, that will help to get the full context here. – Jayant Das Oct 10 '18 at 14:31
2

Looking at your question and comments, I can see following issues. I will strongly recommend to edit your question to put every details in the original post.

  1. You have declared the name of the component event in your registering lightning component as cardSwapRegister
  2. You are trying to set the parameters on the component event in your JS controller using the name as CardOnCardSwap
  3. You have declared the component event in your handler lightning component as cardSwapped

None of the names at any place matches and thus you are encountering the issue where you are not able to set the values, and retrieve the values.

For component events, you communicate between your lightning components using the name. That means that the name in your registering LC and the handler LC should be always same. And that you use the same name in any of the JS controllers too.

This is from the documentation:

The name attribute in <aura:handler> must match the name attribute in the tag in the component that fires the event.

Once you fix the naming issues across the components, you should be able to have it working.

-2

Have you checked if eventtype is COMPONENT or APPLICATION.

Also, you should register the vent in the component markup (aura:registerEvent).

Event calls must have the same name of the registered event.

<aura:registerEvent name="myevent" type="c:MyCustomEvent" />     


component.getEvent("myevent");

$A.get('e.c:NAMEOFEVENT')
  • You can add some more details to make it clear what you are pointing at. – itzmukeshy7 Oct 10 '18 at 17:53

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.