[英]AngularJS pass variable through to a template
I want to pass a variable or text through to a template so that it shows the value inside my template. 我想将变量或文本传递给模板,以使其显示模板中的值。
I come across jsFiddle which shows it working but it uses ng-repeat
. 我碰到jsFiddle ,它显示了它的工作原理 ,但它使用
ng-repeat
。 Is there a simplere way to do this without using ng-repeat
? 有没有不使用
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>
http://jsfiddle.net/f97keutL/ http://jsfiddle.net/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: 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? 您只是在范围内设置变量,并包含模板?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.