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

标签 angular asynchronous rxjs observable

我创建了这个界面:

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/

相关文章:

angular - 如何在 Angular 中测试延迟加载路由的存在?

javascript - karma : Move Folder -> Missing Error Handler on Socket?

Angular - 如何防止具有依赖可观察量的嵌套管道?

javascript - rxjs 流程和 ngrx 选择器的问题

angular - 当另一个 Observable(通知程序)发出时,从源 Observable 发出下一个值

angular - 带有嵌套下拉选项(如 angular1)的 Material 设计 angular2/4 菜单的示例是什么?

javascript - 如何从 Angular5 组件 mydaterangepicker 中删除 "position: absolute"?

node.js - 同一个node.js程序中的异步和同步函数调用

javascript - react-redux with thunk - getState 不是一个函数

jQuery : XMLHttp Requests : Is this use of synchronous ajax bad?