类型错误:Object(...) 不是函数 [英] TypeError: Object(...) is not a function

查看:26
本文介绍了类型错误:Object(...) 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

致力于 ionic3、angularfire2 v5

<块引用>

TypeError: Object(...) is not a function在 SwitchMapSubscriber.project (http://localhost:8100/build/vendor.js:73935:76)在 SwitchMapSubscriber._next (http://localhost:8100/build/vendor.js:61778:27)在 SwitchMapSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)在 RefCountSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)在 RefCountSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)在 Subject.next (http://localhost:8100/build/vendor.js:23237:25)在 ConnectableSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)在 ConnectableSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)在 Notification.observe (http://localhost:8100/build/vendor.js:51866:50)在 AsyncAction.DelaySubscriber.dispatch (http://localhost:8100/build/vendor.js:76246:40)

home.ts

import { Component } from '@angular/core';从'ionic-angular'导入{IonicPage,NavController};import { Observable } from "rxjs/Observable";从../../models/item/item.model"导入{项目};从../../services/shopping-list/shopping-list.services"导入{ShoppingListServices};@IonicPage()@成分({选择器:'主页',模板网址:'home.html'})导出类主页{shoppingList$: Observable;构造函数(公共导航控件:导航控制器,私人购物:ShoppingListServices){this.shoppingList$=this.shopping.getShoppingList().snapshotChanges().地图(变化 =>{返回changes.map(c => ({密钥:c.payload.key, ...c.payload.val()}));});}}

home.html

<ion-navbar color="primary"><离子标题>购物清单</ion-title><离子按钮结束><button navPush="AddShoppingItemPage" ion-button><ion-icon name="add"></ion-icon></离子按钮></ion-navbar></ion-header><离子含量填充><离子列表><离子列表头>项目</ion-list-header><ion-item *ngFor="let item of shoppingList$ | async">{{ 项目名称 }}</ion-item></ion-list></离子含量>

解决方案

这对我有用,使用 "angularfire2": "^5.0.0-rc.11"

npm i rxjs@6 rxjs-compat@6 promise-polyfill --save

检索数据:

this.db.list('/customers').valueChanges().subscribe((datas) =​​> {控制台日志(数据",数据)},(错误)=>{console.log("问题:", 错误)});

或者您可以在 GitHub 存储库中查看 angularfire2 此处了解更多详情

working on ionic3, angularfire2 v5

TypeError: Object(...) is not a function
    at SwitchMapSubscriber.project (http://localhost:8100/build/vendor.js:73935:76)
    at SwitchMapSubscriber._next (http://localhost:8100/build/vendor.js:61778:27)
    at SwitchMapSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
    at RefCountSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)
    at RefCountSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
    at Subject.next (http://localhost:8100/build/vendor.js:23237:25)
    at ConnectableSubscriber.Subscriber._next (http://localhost:8100/build/vendor.js:20786:26)
    at ConnectableSubscriber.Subscriber.next (http://localhost:8100/build/vendor.js:20750:18)
    at Notification.observe (http://localhost:8100/build/vendor.js:51866:50)
    at AsyncAction.DelaySubscriber.dispatch (http://localhost:8100/build/vendor.js:76246:40)

home.ts

import { Component } from '@angular/core';
import {IonicPage, NavController} from 'ionic-angular';
import { Observable } from "rxjs/Observable";
import { Item } from "../../models/item/item.model";
import {ShoppingListServices} from "../../services/shopping-list/shopping-list.services";



@IonicPage()

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  shoppingList$: Observable<Item[]>;
  constructor(public navCtrl: NavController,  private shopping: ShoppingListServices) {
    this.shoppingList$=this.shopping
      .getShoppingList()
      .snapshotChanges()
      .map(
        changes => {
          return changes.map(c => ({
            key: c.payload.key, ...c.payload.val()
          }));
        }
      );
  }

}

home.html

<ion-header>
  <ion-navbar color="primary">
    <ion-title>
      Shoping List
    </ion-title>
    <ion-buttons end>
      <button navPush="AddShoppingItemPage" ion-button>
        <ion-icon name="add"></ion-icon>
      </button>
    </ion-buttons>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <ion-list>
    <ion-list-header>
      Items
    </ion-list-header>
    <ion-item *ngFor="let item of shoppingList$ | async">
      {{ item.name }}
    </ion-item>
  </ion-list>
</ion-content>

解决方案

This works for me, using "angularfire2": "^5.0.0-rc.11"

npm i rxjs@6 rxjs-compat@6 promise-polyfill --save

To retrieve the data:

this.db.list('/customers').valueChanges().subscribe((datas) => { 
  console.log("datas", datas)
},(err)=>{
   console.log("probleme : ", err)
});

Or you can check the GitHub repository for angularfire2 here for more details

这篇关于类型错误:Object(...) 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆