Angular 7:TypeError:如果没有“ new”,则无法调用类构造函数Observable

时间:2019-07-14 16:56:39

标签: firebase-realtime-database angular7

this.db.object('/users/'+user.uid).update({
  name:user.displayName,email:user.email
  });
}

遇到此错误:

core.js:9110 ERROR TypeError: Class constructor Observable cannot be invoked without 'new'
     at new FirebaseObjectObservable (firebase_object_observable.js:16)
     at FirebaseObjectFactory (firebase_object_factory.js:7)
     at AngularFireDatabase.push../node_modules/angularfire2/database/database.js.AngularFireDatabase.object (database.js:18)
     at UserService.save (user.service.ts:20)
     at SafeSubscriber._next (app.component.ts:23)
     at SafeSubscriber.__tryOrUnsub (Subscriber.js:185)
     at SafeSubscriber.next (Subscriber.js:124)
     at Subscriber._next (Subscriber.js:72)
     at Subscriber.next (Subscriber.js:49)
     at Notification.observe (Notification.js:20)
 defaultErrorLogger @ core.js:9110

2 个答案:

答案 0 :(得分:0)

转到tsconfig.json,

将目标从es2015更改为es5。

这对我有用。

我认为当您使用AngularFire数据库方法时,编译器仍然存在问题,我不能100%地确定原因,但是更改目标可以立即解决问题,并且我的用户字段很容易在数据库中创建

答案 1 :(得分:0)

TSCONFIG.JSON中的 TARGET es2015 更改为 es5 然后用ng serve

重新编译