Hi i'm new to angular and firebase and i've been struggling with a simple code since this morning, i've searched about the problem and I didn't find any solution that worked for me (sometimes I didn't even understand it, i'm a real beginner here) the Error i'm having on the console is the following :
Uncaught Error: Unexpected value 'AngularFireDatabase' imported by the module 'AppModule'. Please add a @NgModule annotation. at syntaxError (compiler.js:485) at eval (compiler.js:15225) at Array.forEach () at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15200) at JitCompiler._loadModules (compiler.js:34255) at JitCompiler._compileModuleAndComponents (compiler.js:34216) at JitCompiler.compileModuleAsync (compiler.js:34110) at CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:230) at PlatformRef.bootstrapModule (core.js:5568) at eval (main.ts:11)
here's my code : the 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 { }
the 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 {
}
}
the dependencies of the 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"
}
i've tried to reinstall everything many times but nothing seemed to work, I hope you guys can help me with this
I think yon need to change your imports to replace AngularFireDatabase
with AngularFireDatabaseModule
:
imports: [
...
AngularFireDatabaseModule
],
and remove AngularFireDatabase
from your module imports:
import { AngularFireDatabaseModule } from "angularfire2/database";
you are importing AngularFireDatabase
instead of the module. AngularFireDatabase
should be imported in the component only.