gpt4 book ai didi

angular2 *ngfor 和嵌套可观察

转载 作者:太空狗 更新时间:2023-10-29 18:02:21 25 4
gpt4 key购买 nike

遇到嵌套可观察对象的问题:

我设法制定了正确数量的计划,顺便说一句,所有的 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.
}

我得到的结果是一张包含我的计划的表格,但在同一行上组合是空的:组合中没有选择(异步不工作?)似乎在状态 $ 更新时模板没有更新

谢谢你的帮助!

最佳答案

我想这就是你想要的:

        <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>

关于angular2 *ngfor 和嵌套可观察,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38593776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com