question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Communicating between controllers

See original GitHub issue

I know this isn’t exactly an issue, but I think it is a good question. I think of your controllers as controllers for components on a page. How would you suggest to communicate between more controllers?

I have two components List (data rendered in a list) and ListFilter (bunch of selects and text inputs). List is loaded using AJAX. It should be reloaded every time ListFilter changes. I would like to use separate controllers for List and ListFilter to keep files small and organized.

So, how to trigger a List reload when ListFilter changes?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:38
  • Comments:43 (19 by maintainers)

github_iconTop GitHub Comments

92reactions
georgeclaghorncommented, Jan 4, 2018

From a Controller instance, you can call this.application.getControllerForElementAndIdentifier:

import { Controller } from "stimulus"

export default class ListFilterController extends Controller {
  // ...

  reloadList() {
    this.listController.reload()
  }

  get listController() {
    return this.application.getControllerForElementAndIdentifier(this.element, "list")
  }
}
49reactions
sstephensoncommented, Jan 4, 2018

We don’t have anything built in for this right now. The easiest thing to do is probably to emit a DOM event from the inner controller and observe it with an action from the outer controller.

What I would like to see eventually is a data-outlet attribute that connects delegate properties on a child controller directly to a containing element’s controller. Something like Interface Builder outlets in Cocoa.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the correct way to communicate between controllers in ...
Using $rootScope.$broadcast and $scope.$on for a PubSub communication. Also, see this post: AngularJS – Communicating Between Controllers.
Read more >
Communicating between Beckhoff controllers part 1: EAP
This posts shows an step by step tutorial for communication between Beckhoff controllers using the EtherCAT Automation Protocol (EAP).
Read more >
How to pass data or communicate between Controllers?
The best practice is to have data related to your application in a model class and use the controllers rather than passing data...
Read more >
Use Callbacks to Communicate Between Controllers
For instance, you do not want to abuse this method to trigger actions from other controllers. This would defeat the design of StimulusJS...
Read more >
Communicating between controllers in AngularJS
Communicating between controllers in AngularJS · When referencing 'someEvent' in the view, angular creates a “$watch” for the $scope. · Upon events occurrence...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found