angularjs – 如何使用ng-repeat组件?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何使用ng-repeat组件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这样的代码和平:

<item ng-repeat="name in names"></item>

在item.html中,有很多东西,如name.first,name.family等.
所以,问题是,由于范围的原因,我无法访问名称对象.

我很困惑.组件继承名称至少不应该?

这是我的组成部分:

app.component('item',{
   templateUrl: '/views/item.html'
});

解决方法

这是一个例子 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-repeat循环的数据,以便在组件中访问它.

猜你在找的Angularjs相关文章