I want to pass a variable or text through to a template so that it shows the value inside my template.
I e across jsFiddle which shows it working but it uses ng-repeat
. Is there a simplere way to do this without using ng-repeat
?
<div ng-repeat="name in ['John']" ng-include="'partial.html'"></div>
<div ng-repeat="name in ['Jack']" ng-include="'partial.html'"></div>
<script type="text/ng-template" id="partial.html">
<div>The name is {{ name }}</div>
</script>
I want to pass a variable or text through to a template so that it shows the value inside my template.
I e across jsFiddle which shows it working but it uses ng-repeat
. Is there a simplere way to do this without using ng-repeat
?
<div ng-repeat="name in ['John']" ng-include="'partial.html'"></div>
<div ng-repeat="name in ['Jack']" ng-include="'partial.html'"></div>
<script type="text/ng-template" id="partial.html">
<div>The name is {{ name }}</div>
</script>
Share
Improve this question
asked Nov 19, 2014 at 17:16
ngplaygroundngplayground
21.7k37 gold badges98 silver badges174 bronze badges
2
-
Using just one div??
<div ng-repeat="name in ['John','Jack']" ng-include="'partial.html'"></div>
– Hackerman Commented Nov 19, 2014 at 17:19 - The above divs would be split to other parts of a page so no need for ng-repeat – ngplayground Commented Nov 19, 2014 at 17:20
1 Answer
Reset to default 7http://jsfiddle/f97keutL/
<div ng-controller="ctrl">
<div ng-include="'partial.html'"></div>
</div>
<script type="text/ng-template" id="partial.html">
<div>The name is {{ name }}</div>
</script>
JS:
var myApp = angular.module('myApp',[]);
myApp.controller('ctrl', function($scope) {
$scope.name = "John";
});
You just set the variable in the scope, and include the template?