如何修复Ionic中的“无法设置未定义的属性'bindCallback'”?

时间:2018-12-23 11:28:55

标签: angular ionic-framework ionic3 angularfire2

我正在尝试创建一个将Google Firestore用作数据库的ionic-3应用程序,但我一直遇到错误。

我曾经得到TypeError: Object(...) is not a function,经过一番谷歌搜索后,我尝试通过安装rsjs和rsjs-compat来进行补救。现在,即使我在代码中删除了所有对firebase和rsjx的引用,我也得到了Cannot set property 'bindCallback' of undefined

我还尝试了导入{ Observable } from 'rxjs/Observable'import { Observable } from 'rxjs'的各种排列,但是这些都不能解决问题。

我的软件包版本为: (全局)

  • @ angular / cli @ 7.1.3
  • cordova@8.1.2
  • ionic@4.5.0
  • n@2.1.12

(非全局)

  • @ angular / core @ 5.2.11
  • typescript@2.6.2
  • @ angular / fire @ 5.1.1
  • angularfire2@5.1.1
  • firebase@5.7.1
  • rxjs@6.0.0
  • rxjs@6.3.3

进口:

  • import { Component, Injectable } from '@angular/core';

  • import { IonicPage, NavController, NavParams } from 'ionic-angular';

  • import { AngularFirestore } from 'angularfire2/firestore';

import { Observable } from 'rxjs';

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {

  constructor(public navCtrl: NavController, public navParams: NavParams, private fireStore: AngularFirestore) {
      this.chatDoc = fireStore.doc('chats/test-chat')
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad HomePage');
  }

}

离子错误:

运行时错误

Cannot set property 'bindCallback' of undefined
Stack
TypeError: Cannot set property 'bindCallback' of undefined
at Object.<anonymous> (http://localhost:8100/build/vendor.js:154433:32)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:152110:1)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:49616:10)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:152085:14)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)
at Object.<anonymous> (http://localhost:8100/build/vendor.js:48266:10)
at __webpack_require__ (http://localhost:8100/build/vendor.js:55:30)

Ionic Framework: 3.9.2

Ionic App Scripts: 3.2.1
Angular Core: 5.2.11
Angular Compiler CLI: 5.2.11
Node: 10.14.2
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

1 个答案:

答案 0 :(得分:2)

正如我在这里https://github.com/angular/angular/issues/20095所读,由于打字稿不兼容,因此出现了问题。更新打字稿就可以了。 因此,请在cmd中运行此命令(确保已安装node.js)

npm install -g typescript@latest

然后它应该可以工作^ _ ^。

相关问题