Template with scope value

Description

The following code shows how to use Template with scope value.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from   www.  j a v a  2s .  co m-->
<body ng-app="myApp">
  <script type="text/ng-template" id="/toBeIncluded.html">
    This is a partial with something unique:
    <span>{{partialVar}}</span>
</script>
<div ng-controller="MyCtrl">
    <div ng-repeat="partialVar in partialStuff">
        <div ng-include src="'/toBeIncluded.html'"></div>
    </div>
</div>
<script type='text/javascript'>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
    $scope.partialStuff = [ 'p1', 'p2', 'p3' ];
}
</script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities