angular - 添加可观察的可观察的
问题描述
我正在使用 myObject 数组的 observable 来填充我的 html 模板中的输入类型选择。我希望能够根据条件向我的列表中添加另一个选项。
=> 我想添加myItem = Observable <myObject>
到我的myList = Observable<myObject[]>
我从 http 方法中检索两个 observables。我在文档中找不到任何操作员来执行此操作。
我可以通过像这样订阅 myItem 来做到这一点
myList.pipe(
map(x=> myItem.subscribe(y=> x.push(y)))
)
但我更愿意在没有订阅的情况下这样做。
我的模板就像
<mat-form-field>
<mat-select [value]="selected$ | async" (selectionChange)="getSelectedValue($event)">
<mat-option *ngFor="let item of myList | async" [value]="item.Id">{{item.Name}} </mat-option>
</mat-select>
</mat-form-field>```
解决方案
您可以使用Observable.concat
:
myList = Observable.concat(myList, from(myItem));
推荐阅读
- visual-studio - “获取最新版本”未按预期工作
- java - 子类方法没有正确减去
- javascript - JavaScript:替换部分文本存储在以“$”开头的字符串变量中?
- android - 未解决的参考:“ButterKnife”
- android - ViewPager2 报错 androidx....RecycleView.Adapter) 在 ViewPager2 中无法应用
- java - 恢复具有相关实体的实体列表,同时使用 JPQL 或条件 API 省略某些字段
- postgresql - 在 Postgres 中透视 CTE 的结果
- c++ - 我正在执行数组旋转,但输出不正确。谁能告诉我下面的代码有什么问题?
- python - RNN 和 CNN-RNN 不能正确训练,总是预测一类
- css - 如何使 3 个项目填充具有特定行和列的 6x6 网格?