There are two controllers a and b; there is a click event in controller a. After clicking, how to display a p in control b?
For example: controller a is a menu, controller b is a content area, click on different menus in a, and control the display of different content in b,
Some effort: I tried service and factory, but I can only share data but cannot trigger it in real time
I have tried two methods here:
1. Use angular’s own event mechanism
Used in the controller, add a to send event notification to b:
2. Use service to simulate callback events. The essence is to use service to save a global callback function for use between controllers
Hmm. You can try event bubbling and tunneling mechanisms.
You can take a look at this
To be more direct, you can try $broadcast and $on, but the efficiency will be poor
Seeing that what is written above is not pure enough (it is mixed with other considerations), I will add a pure version.
Demo provided
The code is as follows
1). Create an event bus to manage all events globally
2). Use $broadcast and $emit