嗨,我是角度和火基的新手,从今天早上开始,我一直在努力使用简单的代码,我搜索了这个问题,但我找不到任何对我有用的解决方案(有时我没做过)甚至理解它,我是一个真正的初学者在这里) 我在控制台上遇到的错误如下:
未捕获错误:模块“AppModule”导入的意外值“AngularFireDatabase”。请添加@NgModule注释。 在syntaxError(compiler.js:485) 在eval(compiler.js:15225) 在Array.forEach() 在CompileMetadataResolver.getNgModuleMetadata(compiler.js:15200) 在JitCompiler._loadModules(compiler.js:34255) 在JitCompiler._compileModuleAndComponents(compiler.js:34216) 在JitCompiler.compileModuleAsync(compiler.js:34110) 在CompilerImpl.compileModuleAsync(platform-browser-dynamic.js:230) 在PlatformRef.bootstrapModule(core.js:5568) 在eval(main.ts:11)
这是我的代码: app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireModule } from "angularfire2";
import { AngularFireDatabaseModule, AngularFireDatabase } from "angularfire2/database";
import { AppComponent } from './app.component';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabase
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireDatabase } from "angularfire2/database";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
}
package.json的依赖关系
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/platform-server": "^5.1.2",
"@angular/router": "^5.0.0",
"@angular/service-worker": "^5.1.2",
"angularfire2": "^5.0.0-rc.4",
"core-js": "^2.4.1",
"firebase": "4.8.0",
"ng-push": "^0.2.1",
"ng-pwa-tools": "0.0.15",
"rxjs": "^5.5.2",
"webpack": "^3.10.0",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.6.2",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
我尝试过多次重新安装,但似乎什么都没有用,我希望你们能帮助我这个
答案 0 :(得分:13)
我认为您需要更改导入以将AngularFireDatabase
替换为AngularFireDatabaseModule
:
imports: [
...
AngularFireDatabaseModule
],
并从您的模块导入中删除AngularFireDatabase
:
import { AngularFireDatabaseModule } from "angularfire2/database";
您要导入AngularFireDatabase
而不是模块。 AngularFireDatabase
只能在组件中导入。