Angular 5,可观察和异步功能

编程入门 行业动态 更新时间:2024-10-17 00:21:18
本文介绍了Angular 5,可观察和异步功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在尝试创建类似于http.get(...)的函数,但是不执行任何http.基本上我要做的就是定义一个函数

I have been trying to create a function that is similar to http.get(...) but not doing any http. Basically what I have done is that I defined a function

async myFunc(): Observable<string> { var myObservable: Observable<string>; //..... // the rest of the function's code comes here // ... return myObservable; }

但是我总是收到一个错误消息,它与ES5/ES3不兼容,应该返回Promise对象?但是我想知道Angular 5的http.get函数如何成为可能?显然它返回一个Observable.

But I always get an error that it is not compatible with ES5/ES3 and should return a Promise object? But I am wondering how it became possible with Angular 5's http.get function? Where clearly it returns an Observable.

谢谢,阿塔尼斯(Artanis)

Thanks, Artanis

推荐答案

async/await功能可与promises一起使用.您可以使用 Observable.defer 定义具有async/await功能的Observable.

The async/await functionality works with promises. You can use Observable.defer to define an Observable with async/await functionality.

有关更多信息,请参见此帖子: medium/@benlesh/rxjs-observable-interop-with-promises-and-async-await-bebb05306875

See this post for more information: medium/@benlesh/rxjs-observable-interop-with-promises-and-async-await-bebb05306875

更多推荐

Angular 5,可观察和异步功能

本文发布于:2023-11-13 02:19:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583148.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!