Issue
So I am pretty new to Angular and, currently I am making a clone by using Firebase and all. So, Angular is throwing two error's to me named:
Component AppComponent is standalone, and cannot be declared in an NgModule. Did you mean to import it instead?
The
AppComponent
class is a standalone component, which can not be used in the@NgModule.bootstrap
array. Use thebootstrapApplication
function for bootstrap instead.
This is the app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginComponentComponent } from './login-component/login-component.component';
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { getFirestore, provideFirestore } from '@angular/fire/firestore';
import { MatFormFieldModule } from "@angular/material/form-field";
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent,
LoginComponentComponent
],
imports: [
BrowserModule,
AppRoutingModule,
MatFormFieldModule,
BrowserAnimationsModule,
provideFirebaseApp(() => initializeApp({
apiKey: "YOUR API KEY",
authDomain: "YOUR AUTH DOMAIN",
databaseURL: "YOUR DATABASE URL",
projectId: "YOUR PROJECT ID",
storageBucket: "YOUR STORAGE BUCKET",
messagingSenderId: "YOUR SENDER ID",
appId: "YOUR APP ID",
measurementId: "YOUR MEASUREMENT ID"
})),
provideAuth(() => getAuth()),
provideFirestore(() => getFirestore())
],
providers: [],
bootstrap: [AppComponent]
}
export class AppModule { }
This is the app.compnent.module.ts:
import { Component } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { CommonModule } from '@angular/common';
import { RouterLinkActive, RouterOutlet, RouterLink } from '@angular/router';
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule, RouterOutlet,
RouterLink, RouterLinkActive],
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'zomato-clone';
}
I can't figure out what to do. Can Someone please help? Thank you in advance.
I tried removing the AppComponent from declarations and bootstrap, it did compile but I was not able to see anything on the HTML. I was expecting to see the navbar that I had designed in the html doc, but just saw just a blank page.
Solution
Remove standalone: true
and imports: [CommonModule, RouterOutlet, RouterLink, RouterLinkActive],
from app.component
import { Component } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'zomato-clone';
}
In app.module ts :
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LoginComponentComponent } from './login-component/login-component.component';
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { getFirestore, provideFirestore } from '@angular/fire/firestore';
import { MatFormFieldModule } from "@angular/material/form-field";
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CommonModule } from '@angular/common';
import { RouterLinkActive, RouterOutlet, RouterLink } from '@angular/router';
@NgModule({
declarations: [
AppComponent,
LoginComponentComponent
],
imports: [
BrowserModule,
CommonModule, // add here if necessasry
RouterLinkActive,// add here if necessasry
RouterOutlet, // add here if necessasry
RouterLink,// add here if necessasry
AppRoutingModule,
MatFormFieldModule,
BrowserAnimationsModule,
provideFirebaseApp(() => initializeApp({
apiKey: "YOUR API KEY",
authDomain: "YOUR AUTH DOMAIN",
databaseURL: "YOUR DATABASE URL",
projectId: "YOUR PROJECT ID",
storageBucket: "YOUR STORAGE BUCKET",
messagingSenderId: "YOUR SENDER ID",
appId: "YOUR APP ID",
measurementId: "YOUR MEASUREMENT ID"
})),
provideAuth(() => getAuth()),
provideFirestore(() => getFirestore())
],
providers: [],
bootstrap: [AppComponent]
}
export class AppModule { }
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'zomato-clone';
}
Answered By - Selaka Nanayakkara
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.