AngularJS Example

by netsi1964

HTML

<!-- template1.html -->
  <script type="text/ng-template" id="template1.html">
<div >TEMPLATE 1
        <span ng-repeat="a in data">{{a}}</span>
    </div>
  </script>
  
  <!-- template2.html -->
  <script type="text/ng-template" id="template2.html">
    <ul>
        <li>Template 2</li>
        <li ng-repeat="a in data">{{a}}</li>
    </ul>
  </script>


  <div ng-controller="Ctrl">
    <select ng-model="template" ng-options="t.name for t in templates">
    </select>
    url of the template: <tt>{{template.url}}</tt>
    <hr/>
    <div ng-include src="template.url"></div>
  </div>

JavaScript

function Ctrl($scope) {
  $scope.templates =
    [ { name: 'template1.html'}
    , { name: 'template2.html'} ];
  $scope.template = $scope.templates[0];
    $scope.data = [1,2,3,4,5,6,7,8,9,0]
}