gpt4 book ai didi

angular - ERROR in AppComponent 不能作为入口组件

转载 作者:太空狗 更新时间:2023-10-29 17:25:49 28 4
gpt4 key购买 nike

嘿,我是 Angular 和 Web 开发的新手,我学习了一些教程。

当尝试合并使用我的 Firebase 数据库时,在本地编译(使用 ng serve)时我的应用程序失败了。返回:“AppComponent 不能作为入口组件”

如果您能提供任何帮助,那就太好了。提前致谢:)

//app.component.ts
import { Component } from '@angular/core';
import {AuthService} from "./services/auth.service";
import {Router} from "@angular/router";
import { AngularFireDatabase } from 'angularfire2/database';
import { AngularFireList } from 'angularfire2/database';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

class Event {
constructor(public title) { }
}


export class AppComponent {
title = 'qoqa';
private eventCounter = 0;
public events:AngularFireList<Event[]>;
constructor(db: AngularFireDatabase, private authService: AuthService, private router: Router) {
this.events= db.list('/events');
}
public AddEvent(): void {
let newEvent = new Event(`My event #${this.eventCounter++}`);
this.events.push([newEvent]);
}
signInWithFacebook() {
this.authService.FacebookSignIn()
.then((res) => {
//this.router.navigate(['dashboard'])
})
.catch((err) => console.log(err));
};
signInWithGoogle() {
this.authService.GoogleSignIn()
.then((res) => {
//this.router.navigate(['dashboard'])
})
.catch((err) => console.log(err));
}
}

//app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { environment } from '../environments/environment';
import { LoginComponent } from './login.component';
import { AppRoutingModule } from './app-routing';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AuthService } from './services/auth.service';

import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { CreateEventComponent } from './create-event/create-event.component';
import { EventsComponent } from './events/events.component';
import { ProfileComponent } from './profile/profile.component';
import { SavedEventsComponent } from './saved-events/saved-events.component';
import { InvitationsComponent } from './invitations/invitations.component';
import { CreateQoqaComponent } from './create-qoqa/create-qoqa.component';



@NgModule({
declarations: [
AppComponent,
LoginComponent,
HomeComponent,
CreateEventComponent,
EventsComponent,
ProfileComponent,
SavedEventsComponent,
InvitationsComponent,
CreateQoqaComponent
],
imports: [
AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule,
AngularFireAuthModule,
AngularFireDatabaseModule,
AppRoutingModule,
BrowserModule
],
providers: [AuthService],
bootstrap: [AppComponent]
})
export class AppModule { }

最佳答案

@Component 装饰应该用在 AppComponent 而不是 Event 上。

还要检查 AppComponent 是否在 AppModule 上声明。

关于angular - ERROR in AppComponent 不能作为入口组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52910879/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com