(Highly related to my other question on Programmers.SE: https://softwareengineering.stackexchange.com/questions/280249/whether-to-abstract-small-repeating-code-segments-in-html-templates)
When I want to reuse a few lines of HTML, it is really annoying that I have to write some JavaScript boilerplate in another file just to create a Directive. I really want to create a Directive in mark up in the same HTML file.
Then an idea came to me: I can create a special directive (custom-tag
below) that declares a directive from HTML.
For example:
<custom-tag name="icon" params="{which: '@which'}">
<span class="glyphicon glyphicon-{{which}}" />
</custom-tag>
Which will translate to some JavaScript like:
module.direcrtive('icon', {
restrict: 'E',
scope = {which: '@which'},
template = '<span class="glyphicon glyphicon-{{which}}" />',
});
And I can call it like
<icon which="asterisk" />
My question is does something like this already exist in Angular?
(I know this is just reinventing some other templating frameworks, but I am required to use Angular.)