如何使用ng-repeat组件?

Meh*_*ini 6 angularjs

我有这样的代码和平:

<item ng-repeat="name in names"></item>
Run Code Online (Sandbox Code Playgroud)

而在item.html,有很多东西name.first,name.family等等.
所以,问题是,我不能访问name对象,因为范围的事情.

我很困惑.组件name至少不应该继承吗?

这是我的组成部分:

app.component('item', {
   templateUrl: '/views/item.html'
});
Run Code Online (Sandbox Code Playgroud)

Pri*_*ohn 11

这是一个示例plnkr:

的index.html

  <body ng-controller="MainCtrl">
    <item data="name" ng-repeat="name in names"></item>
  </body>
Run Code Online (Sandbox Code Playgroud)

的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: '='
   }
});
Run Code Online (Sandbox Code Playgroud)

item.html

{{$ctrl.data.first}}
{{$ctrl.data.family}}
<br>
Run Code Online (Sandbox Code Playgroud)

基本上,您需要做的是使用绑定来绑定要使用ng-repeat循环的数据,以便在组件中访问它.