Uncaught Error: Unexpected value 'AngularFireDatabase' imported by the module 'AppModule'. Please add a @NgModule annotation
Uncaught Error: Unexpected value 'AngularFireDatabase' imported by the module 'AppModule'. Please add a @NgModule annotation
嗨,我是 angular 和 firebase 的新手,从今天早上开始我就一直在为一个简单的代码苦苦挣扎,我搜索了这个问题,但没有找到任何适用的解决方案我(有时我什至不明白,我是这里的真正初学者)
我在控制台上遇到的错误如下:
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)
这是我的代码:
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"
}
我已经尝试重新安装很多次了,但似乎没有任何效果,我希望你们能帮助我解决这个问题
我认为你需要更改你的导入以将 AngularFireDatabase
替换为 AngularFireDatabaseModule
:
imports: [
...
AngularFireDatabaseModule
],
并从您的模块导入中删除 AngularFireDatabase
:
import { AngularFireDatabaseModule } from "angularfire2/database";
您正在导入 AngularFireDatabase
而不是模块。 AngularFireDatabase
只应在组件中导入。
嗨,我是 angular 和 firebase 的新手,从今天早上开始我就一直在为一个简单的代码苦苦挣扎,我搜索了这个问题,但没有找到任何适用的解决方案我(有时我什至不明白,我是这里的真正初学者) 我在控制台上遇到的错误如下:
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)
这是我的代码: 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"
}
我已经尝试重新安装很多次了,但似乎没有任何效果,我希望你们能帮助我解决这个问题
我认为你需要更改你的导入以将 AngularFireDatabase
替换为 AngularFireDatabaseModule
:
imports: [
...
AngularFireDatabaseModule
],
并从您的模块导入中删除 AngularFireDatabase
:
import { AngularFireDatabaseModule } from "angularfire2/database";
您正在导入 AngularFireDatabase
而不是模块。 AngularFireDatabase
只应在组件中导入。