【问题标题】:Why Angular 6 app throwing error while deploying for production?为什么 Angular 6 应用程序在部署生产时抛出错误?
【发布时间】:2019-06-20 20:29:58
【问题描述】:

我已经集成了 ngx-Pagination,当我在本地测试它时它工作正常,但是当我以 ng build --prod 运行命令时,它显示错误 ERROR in ./src/ 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>

【问题讨论】:

  • 你需要分享一些代码。用这么少的信息很难说什么。
  • 那么,您指的是应用程序组件中的collection,而是在应用程序模块类中声明和填充collection?这对你有用吗?
  • 请立即查看
  • 我相信这个错误是因为 Angular 无法确定 HomeComponent 类的模块,这可以通过将所述组件添加到 NgModule 来解决。只是一个疯狂的猜测。
  • 意思是......?

标签: angular angular5 angular6


【解决方案1】:

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

尝试在你的 AppModule 声明中添加 HomeComponent

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

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

 }

【讨论】:

  • ./src/app/app.component.ngfactory.js 中的错误找不到模块:错误:无法解析'../../node_modules/ngx-Pagination/dist/ngx- 'D:\paginationdemo\src\app'中的 pagination.ngfactory'
【解决方案2】:

尝试 ng build,因为编译器并不关心你是否声明了变量,但在 prod 模式下,它被设置为 strict。

【讨论】:

    猜你喜欢
    • 2019-07-13
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2020-03-01
    • 1970-01-01
    • 2015-08-02
    • 2016-04-10
    相关资源
    最近更新 更多