2016-07-26 92 views
4

得到了与嵌套观察到的一个问题:我管理的有计划的权数angular2 * ngfor和嵌套观察到

, BTW所有wariable非常的设置,我可以在控制台看到的状态数正在成长...
但组合框是空的我做错了什么?

这里是代码,我在我的模板的一个片段:

<tr *ngFor="let plan of plans$ | async"> 
    <td><input type="text" [(ngModel)]="plan.libelle"/></td> 
    <td> 
     <select> 
      <option *ngFor="let statut of statuts$ | async" 
        ngValue="{{statut.id}}" 
        [selected]="statut.id == plan.statut.id"> 
       {{statut.libelle}} 
      </option> 
     </select> 
    </td> 
</tr> 

的另一个在我的组件:

private plans$:Observable<Array<Plan>>; 
private statuts$:Observable<Array<Param>>; 

constructor(private planService:PlanService, private paramService:ParamService) {} 

ngOnInit() { 
    this.statuts$ = this.paramService.typesPlan$; //return the observable from the service 
    this.plans$ = this.planService.plans$; //same thing 
    this.paramService.loadAll('plan'); //this load all the status in an async way. 
    this.planService.loadAll(); //the same as above and it work. 
} 

结果我已经是蒙山我的计划,但对表同一行的组合是空的:在组合中没有选择(异步不工作?) 它似乎像状态$更新时模板没有更新

感谢您的帮助!

回答

0

我通过修改templete和组件解决了我的问题和组件t:

private plans$:Observable<Array<Plan>>; 
private statuts:Array<Param>; 

constructor(private planService:PlanService, private paramService:ParamService) {} 

ngOnInit() { 
    this.paramService.typesPlan$.suscribe((status)=> this.status = status); 
    this.plans$ = this.planService.plans$; 
    this.paramService.loadAll('plan'); //this load all the status in an async way. 
    this.planService.loadAll(); //the same as above and it work. 
} 
0

我想这是你想要的东西:

<tr *ngFor="let plan of plans$ | async"> 
<td><input type="text" [(ngModel)]="plan.libelle"/></td> 
<td> 
    <select> 
     <option *ngFor="let statut of statuts" 
       ngValue="{{statut.id}}" 
       [selected]="statut.id == plan.statut.id"> 
      {{statut.libelle}} 
     </option> 
    </select> 
</td> 

 <option *ngFor="let statut of statuts$ | async" 
       [(ngValue)]="statut.id"> 
      {{statut.libelle}} 
     </option> 

 <option *ngFor="let statut of statuts$ | async" 
       [ngValue]="plan.statut.id" 
       (ngValueChange)="status.id = $event"> 
      {{statut.libelle}} 
     </option> 
+0

问题发生时,我有两个异步嵌套...如果我把选项标签外tr,它工作得很好。但那不是我想要的:'( –