Unable to send params to function

Hi!

I am new at using in Stimulus, and I have tried to send a param into a function. I have been reading the guide:

https://stimulus.hotwired.dev/reference/actions#action-parameters

I have:

<div data-controller="subscribe">
	<button data-action="click->subscribe#upvote"
		data-item-id-param="1234567890">…</button>
</div>

and

// assets/controllers/subscribe-controller.js
import { Controller } from '@hotwired/stimulus';

/* stimulusFetch: 'lazy' */
export default class extends Controller {
	
	upvote(event){
		console.log(event);
	}
	
}

It call the function but event.params is always:

params: {}

What am I doing wrong?
Thanks

I might be wrong but I think it’s because in the example in the docs, the controller is ItemController and that’s why you can call data-item-id-param.

Maybe try to call the param data-subscribe-id-param to see if you get something.

1 Like