我想将变量或文本传递给模板,以便它在我的模板中显示值。
我遇到了jsFiddle这表明它可以工作,但它使用 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>
最佳答案
<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";
});
你只是在范围内设置变量,并包含模板?
关于javascript - AngularJS 将变量传递给模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27022920/