为什么在部署生产时Angular 6应用抛出错误?

时间:2018-11-22 15:17:53

标签: angular angular5 angular6

我已经集成了ngx-Pagination,并且在本地测试时可以正常工作,但是当我以 ng build --prod 的身份运行命令时,它向我显示./src/中的错误 ERROR app / myads / myads.component.ngfactory.js  error

如果有人知道解决方案,请回答。

app.module.ts

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

import { FormsModule } from "@angular/forms";

import { AppComponent } from './app.component';
import { NgxPaginationModule } from "ngx-Pagination";


@NgModule({
  declarations: [
    AppComponent,

  ],
  imports: [
    BrowserModule,    
    FormsModule,
    NgxPaginationModule    

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {     

 }

app.component.ts

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  collection = ['r', 'k', 'u', 'jj'];
  constructor() { 

  }


}

app.component.html

<ul>
  <li *ngFor="let item of collection | paginate: { itemsPerPage: 2, currentPage: p }">Hello</li>
</ul>  
<pagination-controls (pageChange)="p = $event"></pagination-controls>

2 个答案:

答案 0 :(得分:1)

我猜您有一个未在任何模块中声明的HomeComponent?

尝试在AppModule声明中添加HomeComponent

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule,    
    FormsModule,
    NgxPaginationModule    

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {     

 }

答案 1 :(得分:1)

尝试 ng build ,因为编译器不在乎是否声明了变量,但是在prod模式下,此选项设置为strict。