0
我想在子组件中使用ng-repeat,使用定义的列表是父组件 - 在控制器中。然而,它唯一的工作方式是当我指定该列表来自父代AngularJS ng父亲的范围重复
{$parent.list}
这是正确的方法吗?我可以避免它吗?
var myApp = angular.module('myApp', []);
myApp.component('parent', {
restrict: 'E',
controller: 'parentController',
transclude: true,
template: '<h1>List</h1><div ng-transclude></div>'
}).controller('parentController', function($scope) {
\t $scope.list = ['one','two'];
});
myApp.component('child', {
restrict: 'E',
bindings: {
name: '<',
list: '<'
},
template: '<h3>Child {{$ctrl.name}}</h3>'
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<div ng-app="myApp">
<parent>
<child list="list" ng-repeat="name in list" name="name"></child>
<child list="list" ng-repeat="name in $parent.list" name="name"></child>
</parent>
</div>