AngularJS将变量传递给模板

ngp*_*und 2 html javascript jquery angularjs

我想将变量或文本传递给模板,以便它显示模板中的值.

我遇到了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>
Run Code Online (Sandbox Code Playgroud)

dav*_*ave 6

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>
Run Code Online (Sandbox Code Playgroud)

JS:

var myApp = angular.module('myApp',[]);

myApp.controller('ctrl', function($scope) {
    $scope.name = "John"; 
});
Run Code Online (Sandbox Code Playgroud)

您只需在范围中设置变量,并包含模板?