Angular JavaScript页面可编译但显示为空白

时间:2020-03-28 22:39:50

标签: javascript angular typescript

当我编译Angular应用程序时,它可以工作,但是HTML页面为空白,并且我的应用程序将不会显示。我以前遇到过这样的问题,通常它一直是Imports之一,但是现在我不确定。当我使用Google Chrome浏览器进行检查时,看到的错误是 record.factory不是函数。有人熟悉吗?

这是我的module.ts代码:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';  
import { ItemService } from './items.service';
import { NewItemFormComponent } from './new-item-form/new-item-form.component';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';



@NgModule({
  declarations: [
    AppComponent,
    NewItemFormComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    BrowserAnimationsModule,
    FormsModule
  ],
  providers: [ItemService, BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    BrowserAnimationsModule,
    FormsModule],
  bootstrap: [AppComponent]
})
export class AppModule { }

1 个答案:

答案 0 :(得分:2)

您将几个模块放置在错误的位置。您应该将它们放入imports部分,而不是providers部分。我在说

BrowserModule,
AppRoutingModule,
HttpClientModule,
MatFormFieldModule,
MatInputModule,
BrowserAnimationsModule,
FormsModule

如果您将@Injectable@NgModule装饰器添加到同一类中,那么也会有问题。