hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.74k stars 427 forks source link

Call another controller method from controller #637

Closed helmiattastify closed 1 year ago

helmiattastify commented 1 year ago

Hello, I'm new to stimulus

So, the case is I want to access another method controller from the controller

_controllers/toastcontroller.js

import { Controller } from "@hotwired/stimulus"
import Swal  from "sweetalert2"
export default class extends Controller {
    show(){
    }
   confirm(){
    }
}

_controllers/maincontroller.js

import { Controller } from "@hotwired/stimulus"
import Toast from "./toast_controller"
export default class extends Controller {
    connect(){
       Toast.show();
    }
   confirm(){
    }
}

Still failed,

I haven't met a good tutorial yet. any one can help?

lb- commented 1 year ago

Stackoverflow or the Stimulus discussion forum may be better for this kind of question.

https://stackoverflow.com/questions/tagged/stimulusjs https://discuss.hotwired.dev/

You may also need to have more details in your question.

marcoroth commented 1 year ago

Hey @helmiattastify, adding to what @lb- said, you can also join the Hotwire Discord for more interactive help.

There are a few routes that you can do to solve your problem.

I hope this helps! 🙌🏼