angular async for observable如何显示字段?

时间:2018-05-30 10:53:00

标签: angular

$ app是Obseravable,

当我使用时:

email::::: {{ app$ | async }}

我上了屏幕:

email::::: [object Object]

但如果我使用:

email::::: {{ app$.email | async }}

我上了屏幕:

email:::::

与控制台上的错误一起:

MyComponent.html:3 ERROR Error: InvalidPipeArgument: 'true' for pipe 'AsyncPipe'
    at invalidPipeArgumentError (common.js:4232)
    at AsyncPipe.push../node_modules/@angular/common/fesm5/common.js.AsyncPipe._selectStrategy (common.js:4839)
    at AsyncPipe.push../node_modules/@angular/common/fesm5/common.js.AsyncPipe._subscribe (common.js:4829)
    at AsyncPipe.push../node_modules/@angular/common/fesm5/common.js.AsyncPipe.transform (common.js:4811)
    at Object.eval [as updateDirectives] (SocialLoginComponent.html:3)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:11914)
    at checkAndUpdateView (core.js:11307)
    at callViewAction (core.js:11548)
    at execComponentViewsAction (core.js:11490)
    at checkAndUpdateView (core.js:11313)

如何使用async修饰符打印app$.email

1 个答案:

答案 0 :(得分:4)

您需要使用异步管道等待observable的发射。一旦它发出,你就可以访问带有电子邮件属性的对象。通过将订阅包装在括号中,您可以访问电子邮件属性,如下所示:

{{ (app$ | async).email }}