我创建了这个界面:
interface IGame {
name: string;
description: string;
}
我将它用作 Observable 并将其作为 Input
传递给 Component
:
@Input() public game: Observable<IGame>;
我可以看到使用 JSON 管道打印的值:
<h3>{{game | json}}</h3>
绑定(bind)到特定属性时,不显示任何内容(只是一个空字符串):
<h3>{{game.name}}</h3>
<h3>{{game.description}}</h3>
最佳答案
async
管道在 View 绑定(bind)中进行订阅
<h3>{{(game | async)?.name}}</h3>
?
仅在可能发出 null
值时才需要。
关于 Angular 模板 : How to bind RXJS Observable and read its properties?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672052/