The best way to call a function on one directive from another directive

47 views
Skip to first unread message

Garey Mills

unread,
May 12, 2020, 10:09:27 AM5/12/20
to Angular and AngularJS discussion
I have a directive that models and displays a game board. When a piece is captured on the board, I want that to be recorded and displayed in another widget, which will probably have to be a directive) on the same page as the board directive. I cannot see the way to call a function on the recording directive. I have read the developer's guide for directives carefully, but it seems to be very complex for what seems a simple action. How do you, from a directive, call a function on another directive that increments or decrements a variable on the called directive?


Any help would be appreciated. 

bastien lemaire

unread,
May 12, 2020, 10:21:59 AM5/12/20
to ang...@googlegroups.com
Hey,

The idea is fine but this is done via a service or a store or a global state. Both the main page and the directive would be listening to events, data changes in the service...
Hope this helps

Bastien Lemaire


On Tue, 12 May 2020 at 16:09, Garey Mills <garey...@gmail.com> wrote:
I have a directive that models and displays a game board. When a piece is captured on the board, I want that to be recorded and displayed in another widget, which will probably have to be a directive) on the same page as the board directive. I cannot see the way to call a function on the recording directive. I have read the developer's guide for directives carefully, but it seems to be very complex for what seems a simple action. How do you, from a directive, call a function on another directive that increments or decrements a variable on the called directive?


Any help would be appreciated. 

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/8e25393e-7ea0-407a-be77-201602c18bcb%40googlegroups.com.

Garey Mills

unread,
May 12, 2020, 10:48:41 AM5/12/20
to ang...@googlegroups.com
Thanks. I'll look at services. Part of the problem is the recorder has to show the number of pieces captured, and be available for a drag and drop of the pieces back on to the board.

You received this message because you are subscribed to a topic in the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/7CsAtnl1tRk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/CAJ7E9zF8q4NC8ZOSEK3vb-JDNAa7u%3DpaW7wDBgupsPo-xyF4_w%40mail.gmail.com.


--
The brain is not where you think.
Me


Garey Mills

unread,
May 12, 2020, 1:13:49 PM5/12/20
to ang...@googlegroups.com
I don't see how to use services, and I don't have any information about stores or global states. If possible, would you point me to any information?
Reply all
Reply to author
Forward
0 new messages