angularjs - Declare Angular Directives purely in HTML? -
(highly related other question on programmers.se: https://softwareengineering.stackexchange.com/questions/280249/whether-to-abstract-small-repeating-code-segments-in-html-templates)
when want reuse few lines of html, annoying have write javascript boilerplate in file create directive. want create directive in mark in same html file.
then idea came me: can create special directive (custom-tag
below) declares directive html.
for example:
<custom-tag name="icon" params="{which: '@which'}"> <span class="glyphicon glyphicon-{{which}}" /> </custom-tag>
which translate javascript like:
module.direcrtive('icon', { restrict: 'e', scope = {which: '@which'}, template = '<span class="glyphicon glyphicon-{{which}}" />', });
and can call like
<icon which="asterisk" />
my question exist in angular?
(i know reinventing other templating frameworks, required use angular.)
there (afaik) 3 ways reference template in angular:
as mentioned in question, 1 can put markup directly in
template
propertythe template can referenced via
templateid
in separated filethe template can defined within same page in
<script type="text/ng-template" id="template_id.html"> .... </script>
. , referenced viatemplateid: "template_id.html"
. more details on this: using inline templates in angular
Comments
Post a Comment