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

时间:2014-07-18 08:33:20

标签: dart angular-dart

我们说我有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>

1 个答案:

答案 0 :(得分: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>

未经测试