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 property

  • the template can referenced via templateid in separated file

  • the template can defined within same page in <script type="text/ng-template" id="template_id.html"> .... </script>. , referenced via templateid: "template_id.html". more details on this: using inline templates in angular


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -