我已经集成了ngx-Pagination,并且在本地测试时可以正常工作,但是当我以 ng build --prod 的身份运行命令时,它向我显示./src/中的错误 ERROR app / myads / myads.component.ngfactory.js
如果有人知道解决方案,请回答。
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>
答案 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。