I initially put it in rootScope, and found that it was a global attribute, so I gave up.
I didn’t want to write it in every controller that needed to be used, so I chose to put it in the controller in the directive. Later, I discovered that directives depend on HTML. If the method is the same but my HTML is different, the directive cannot be used.
It’s a bit confusing. What I mean is: One of my methods may be used everywhere, where do I need to put it? Call the method directly when it is needed in the future.
For example: how to write it as public code
Best to use
service
或者factory
For the situation in the screenshot