如何在 Ionic 中修复 "Cannot set property 'bindCallback' of undefined"?
How to fix "Cannot set property 'bindCallback' of undefined" in Ionic?
我正在尝试创建一个使用 google firestore 作为数据库的 ionic-3 应用程序,但我不断收到错误。
我曾经得到 TypeError: Object(...) is not a function
,经过一些谷歌搜索后,我试图通过安装 rsjs 和 rsjs-compat 来补救。现在我得到了 Cannot set property 'bindCallback' of undefined
,即使我在代码中删除了所有对 firebase 和 rsjx 的引用。
我也尝试了导入 { 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');
}
}
来自 Ionic 的错误:
运行时错误
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
正如我在这里读到的那样 https://github.com/angular/angular/issues/20095 ,问题的发生是因为打字稿不兼容。更新打字稿应该可以完成工作。
所以 运行 在 cmd 中这个(确保你已经安装 node.js)
npm install -g typescript@latest
那应该可以了^_^.
我正在尝试创建一个使用 google firestore 作为数据库的 ionic-3 应用程序,但我不断收到错误。
我曾经得到 TypeError: Object(...) is not a function
,经过一些谷歌搜索后,我试图通过安装 rsjs 和 rsjs-compat 来补救。现在我得到了 Cannot set property 'bindCallback' of undefined
,即使我在代码中删除了所有对 firebase 和 rsjx 的引用。
我也尝试了导入 { 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');
}
}
来自 Ionic 的错误:
运行时错误
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
正如我在这里读到的那样 https://github.com/angular/angular/issues/20095 ,问题的发生是因为打字稿不兼容。更新打字稿应该可以完成工作。 所以 运行 在 cmd 中这个(确保你已经安装 node.js)
npm install -g typescript@latest
那应该可以了^_^.