所以我是Angular的新手,目前我正在使用Firebase和其他东西来克隆Angular。所以,Angular向我抛出了两个错误,名为:
1.组件AppComponent是独立的,不能在NgModule中声明。您是否打算改为导入它?
AppComponent
类是一个独立的组件,不能在@NgModule.bootstrap
数组中使用。请改用bootstrapApplication
函数进行引导。
下面是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 { }
字符串
这是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';
}
型
我不知道该怎么办。有人能帮帮忙吗?先谢谢你了。
我试着从声明和 Bootstrap 中删除AppComponent,它确实编译了,但我在HTML上看不到任何东西。我希望看到我在HTML文档中设计的导航栏,但只看到一个空白页面。
1条答案
按热度按时间cld4siwp1#
从
app.component
中删除standalone: true
和imports: [CommonModule, RouterOutlet, RouterLink, RouterLinkActive],
字符串
在应用程序模块ts中:
型