Hey I'm new to using Angular and web development, I've been walking through a few tutorials.
When trying to incorporate use of my Firebase Database, upon compilation locally (using ng serve) my application is failing. Returning: "AppComponent cannot be used as an entry component"
If you could offer any help that'd be great. Thanks in advance :)
//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 { }
A bootstrapped component is an entry component that Angular loads into the DOM during the bootstrap process (application launch). Other entry components are loaded dynamically by other means, such as with the router. Angular loads a root AppComponent dynamically because it's listed by type in @NgModule. bootstrap .
Routed entryComponent: This sort of components are declared components and are added as an array inside the declarations section of the app. But, you may need to reference to a component by its class. Router components are not specified explicitly in the HTML of a component but, are registered in routes array.
A bootstrap component is automatically added to entryComponents. A list of components that can be dynamically loaded into the view.
So when an Angular application is started, the main. ts file is loaded first, here we bootstrap the root module i.e. app.
I just wanted to supply an example of the problem explained by @ibenjelloun.
@Component({ ... })
, while looking a bit like a normal function-call, is a actually a decorator, so it must precede the class that you want Angular to treat as a component. So make sure not to put classes between @Component({ ... })
and export class YourComponent
.
So move Event
to before/after AppComponent
:
class Event {
constructor(public title) { }
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With