处理AngularDart中的子组件时的特定设计问题

问题描述 投票:2回答:1

假设我有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>
dart angular-dart
1个回答
1
投票

如果你想这样做,你需要@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>

not tested

© www.soinside.com 2019 - 2024. All rights reserved.