You need to define a <template>
to be able to use it elsewhere in your app as a TemplateRef
. You can store these TemplateRef
s in a Service and then access them from any @Directive
or @Component
in your app.
What are the actual use cases of directives? Mostly all the functionality is done via component. Then why should someone use directive? It would be very helpful if you provide some real application use case.
@gaurav, I think the real meaning is to add additional behavior to the components without changing the component itself. By doing that you do not mess you component with the whole bunch of possible side scenarios and extract that scenarios to the directives. For example remember the 'track' example from this course, when the tracking logic was placed in the directive and not in the component itself thus making it lean and focused only on its own goal.