加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 在地图后显示可观察的

发布时间:2020-12-17 16:59:32 所属栏目:安全 来源:网络整理
导读:我尝试显示项目列表的一部分(分页). 我的模板: div class="notif" *ngFor="let notif of paginate() | async" {{notif.name}}/div 在我的组件中如果我这样做: public notifications: ObservableNotification[];public paginate(): ObservableNotification[
我尝试显示项目列表的一部分(分页).
我的模板:

<div class="notif" *ngFor="let notif of paginate() | async">
    {{notif.name}}
</div>

在我的组件中如果我这样做:

public notifications: Observable<Notification[]>;
public paginate(): Observable<Notification[]> {
    return this.notifications;
  }

这是有效的,但如果我这样做:

public notifications: Observable<Notification[]>;
public paginate(): Observable<Notification[]> {
  return this.notifications.map((notif: Notification[]) => {
    return notif;
  });

它不再起作用了(我已经简化了功能以了解发生了什么).
.map返回一个可观察的权利?它应该双向工作吗?

解决方法

这是错误的,因为您尝试在返回Observable of Notification []的函数中返回Notification [],因此无效.
如果您需要Notification [],那么您需要订阅Observable.

您无法将Observable映射到其他类型.

例如

public paginate(): Observable<Notification[]> {
  return this.notifications;
  });


notificationArr: Notification[];

// This needs to be inside a method not in the class declaration of variables and methods
paginate().subscribe((notif: Notification[]) => {
return (this.notificationArr = notif);

  }); // should populate your array

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读