Showing posts with label ng-include. Show all posts
Showing posts with label ng-include. Show all posts

Wednesday, 18 May 2016

Template rendering by using ng-include directive

Ng-include:
Fetches, compiles and includes an external HTML fragment.

template1.html
<h1> Hello !! I am from template1 </h1>

Index.html
<div ng-controller="ExampleController">
  <h1>Hello From index</h1>
  <div>
    <div ng-include="template1.html "></div>
  </div>
</div>

Output:

Hello From index
Hello!! I am from template1


Wednesday, 4 May 2016

Reuse html code snippet in angular

<script type='text/ng-template' id="mySnippet"> 
   <h1> Reuse this template </h1>
</script> 
<ng-include src="'mySnippet'"></ng-include>
<ng-include src="'mySnippet'"></ng-include>

script

Load the content of a <script> element into $templateCache, so that the template can be used byngIncludengView, or directives. The type of the <script> element must be specified astext/ng-template, and a cache name for the template must be assigned through the element's id, which can then be used as a directive's templateUrl.