Angularfire2错误TS2305 [英] Angularfire2 error TS2305

查看:575
本文介绍了Angularfire2错误TS2305的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的离子框架的世界,现在我正在尝试创建一个学校项目的应用程序。
要保存应用程序中的数据,我将使用firebase(第一次)。我尝试导入Angularfire和FirebaseListObservable到我的.ts文件,但我得到这个错误信息:

TS2305:Module'C:/ Users / matss / myRecords / node_modules / angularfire2 / index'没有导出成员'AngularFire'。



这里是我在app.module.ts中的导入

 从'angularfire2'导入{AngularFireModule}; 
$ b $导出常量firebaseConfig = {
apiKey:blablabla,
authDomain: blablabla,
databaseURL:blablabla,
projectId:blablabla,
storageBucket:blablabla,
messagingSenderId:blablabla
};

这里是我在excersises.ts中的代码,它给出了错误消息:

 从'angularfire2'导入{AngularFire,FirebaseListObservable}; 

构造函数(private navParams:NavParams,public nacCtrl:NavController,af:AngularFire){
this.records = af.database.list('/ records');

}

作为一个新手,我还没有找到任何好的教程,我可能会在我的搜索中使用错误的关键字。
但是对于这个接下来的教程:
https ://www.joshmorony.com/building-a-crud-ionic-2-application-with-firebase-angularfire/



感谢您的帮助。

解决方案

我遇到了同样的问题,但我能解决它。我读了Josh的文章,因为我读了他所有的,他是非常好的,但最近AngularFire2更新了我所了解,并导致了一些变化。



我解决了这个问题:

 从'angularfire2 / database'导入{AngularFireDatabase,FirebaseListObservable}; 

我还从'angularfire2'导入了 import {AngularFireModule}; 而不是
code从'angularfire2'导入{AngularFire};



据我所知,他们将模块化的程度更高,以便人们可以使用他们想要的功能,而不用花费所有的开销。我可能是错误的,但是。

然而,这对我有用。

所以,用你的代码,它应该看起来像这样:
$ b $ p

在你的app.module.ts文件中:

 从'angularfire2 / database'导入{AngularFireDatabaseModule}; 
从'angularfire2'导入{AngularFireModule};

然后在@NgModule标记下导入它,如下所示:

 进口:[
AngularFireModule.initializeApp(firebaseConfig),
AngularFireDatabaseModule
]

然后在你正在使用的组件ts下。执行以下操作:
$ b $ pre $ 从'angularfire2 / database'导入{AngularFireDatabase,FirebaseListObservable};

之后您需要声明它

 记录:FirebaseListObservable< any []>; 

在您的构造函数中:

pre > 构造函数(private navParams:NavParams,public nacCtrl:NavController,db:AngularFireDatabase){
this.records = db.list('/ records');}


I'm new to the ionic framework world and now I'm trying to create a app for a schoolproject. To save data in the app I'll be using firebase (for the first time). I try to import Angularfire and FirebaseListObservable to my .ts file but i get this error message:

"TS2305:Module "'C:/Users/matss/myRecords/node_modules/angularfire2/index"' has no exported member 'AngularFire'.

Here's my import in app.module.ts

import { AngularFireModule } from 'angularfire2;

export const firebaseConfig = {
apiKey: "blablabla",
authDomain: "blablabla",
databaseURL: "blablabla",
projectId: "blablabla",
storageBucket: "blablabla",
messagingSenderId: "blablabla"
};

here's my code in excersises.ts, which gives the errormessage:

import { AngularFire, FirebaseListObservable } from 'angularfire2';

  constructor(private navParams: NavParams, public nacCtrl: NavController, af: AngularFire){
this.records = af.database.list('/records');

}

As a rookie to this, I haven't found any "good" tutorials, I might use the wrong keywords in my searches.. But for this I followed this tutorial: https://www.joshmorony.com/building-a-crud-ionic-2-application-with-firebase-angularfire/

Thanks for your help.

解决方案

I ran into the same issue, however I was able to solve it. I read Josh's article, as I read all of his and he is really good, but recently AngularFire2 was updated from what I understand and that has caused a few changes.

How I solved it was like this:

import {AngularFireDatabase, FirebaseListObservable} from 'angularfire2/database';

I also imported import { AngularFireModule } from 'angularfire2'; instead of import { AngularFire } from 'angularfire2';

From what I understand, they are modularising it a lot more so that people can use the functions they want and not have all the overhead. I might be wrong though.

This did work for me however.

So, with your code, it should now look like this:

In your app.module.ts file:

import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireModule } from 'angularfire2';

Then import it under the @NgModule tag imports like so:

  imports: [
    AngularFireModule.initializeApp(firebaseConfig),
    AngularFireDatabaseModule 
]

Then under your component ts that you are working with. do the following:

import {AngularFireDatabase, FirebaseListObservable} from 'angularfire2/database';

Then later on you would need to declare it

records: FirebaseListObservable<any[]>;

In your constructor:

constructor(private navParams: NavParams, public nacCtrl: NavController, db: AngularFireDatabase){
    this.records = db.list('/records');}

这篇关于Angularfire2错误TS2305的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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