gpt4 book ai didi

Angular 模板 : How to bind RXJS Observable and read its properties?

转载 作者:太空狗 更新时间:2023-10-29 16:48:25 26 4
gpt4 key购买 nike

我创建了这个界面:

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/

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