假设我有2个组件,cmp1cmp2cmp1将遍历列表,并为每个项目创建cmp2。在cmp2中,我想显示人员数据。

//component 1
@Component(selector: 'cmp1',
           templateUrl: 'cmp1.html',
           publishAs: 'cmp')
class cmp1 {
  List myList;

  cmp1(){
    this.myList = [{'name':'foo','age':20},{'name':'bar','age':30}];
  }
}

cmp1.html
<cmp2 ng-repeat='person in cmp.myList'></cmp2>

//component 2
@Component(selector: 'cmp2',
           templateUrl: 'cmp2.html',
           publishAs: 'cmp')
class cmp2 {}

cmp2.html
<span>name: *display person name*</span>

最佳答案

如果您想以这种方式进行操作,则需要在@NgAttr('person') Map person;中添加一个cmp2

// cmp1.html

<cmp2 person="{{person}}" ng-repeat="person in cmp.myList"></cmp2>

// cmp2.html

<span>name: {{cmp2.person['name']}}</span>

未经测试

关于dart - 在AngularDart中处理子组件时的特定设计问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24820598/

10-10 17:56