下面是一个例子plnkr:
的index.html
<body ng-controller="MainCtrl">
<item data="name" ng-repeat="name in names"></item>
</body>
的script.js
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.names = [{family: "asdf", first: "test"}, {family: "qwerty", first: "test2"}]
});
angular.module('plunker').component('item', {
templateUrl: 'item.html',
bindings: {
data: '='
}
});
item.html
{{$ctrl.data.first}}
{{$ctrl.data.family}}
<br>
基本上你所要做的就是使用绑定到你与NG-重复你的组件中访问循环中的数据绑定的东西。
在这个HTML页面的控制器中是否有变量'$ scope.name'? –
@TimBiegeleisen'item.html'本身没有控制器。但是它的父项'items.html'有一个控制器,它将'names'设置为一个数组。 –