简体   繁体   中英

Get angular directive by name

I know that we can get services from $injector by their name. Is it possible to somehow get the directive/component object from the dependency injector?

For example, if I wanted to write a service that can take a component's name, retrieve the component and do something with retrieved properties, how would I be able to retrieve the component by its name?

You can get services from $injector because there is only a single instance of each service in the system: they are singletons .

On the other hand, Directives/components have multiple instances for each time they show up on the page. Moreover, they cannot be injected as they are always created and bound to HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM