ngx-pagination: "ERROR in Ng2PaginationModule is not an NgModule" after compiling succesfully
Angular 2 version: 2.3.1
ng2-pagination version: 2.0.0
Description of issue:
After importing the Ng2PaginationModule in my app.module.ts
, everything works, but after building (angular-cli@latest) it outputs an error: ERROR in Ng2PaginationModule is not an NgModule
Steps to reproduce: Simply install using NPM and use in your application.
import { Ng2PaginationModule } from 'ng2-pagination';
...
@NgModule({
imports: [
BrowserModule,
Ng2PaginationModule,
FormsModule,
HttpModule
],
...
Expected result: Everything should compile without errors. Actually, it compiles and outputs all bundle files, but after it’s done it still throws an error, messing with my teamcity build.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 19 (9 by maintainers)
<pagination-controls (pageChange)=“p = $event”></pagination-controls>
export class XComponent { … p: number;
just add p in your typescript, add should be work. (test it on my app with ng cli 1.0.0à ng build --prod
@NYearOldCoder The reason is that
ng build
does not do the step of compiling your templates into TypeScript, which does happen then you use the--prod
flag. Once a template is compiled into a TypeScript class, it becomes apparent that the variable “p” does not exist on the component, leading to the error.In dev mode (
ng build
) this compilation step happens dynamically at run-time, and therefore the TypeScript compiler does not get a chance to complain about it.@NYearOldCoder I just did the followingL
npm install
ng build --prod
And got the following error
Is this the same error you get? The reason for this error is that in list.component.html template, you refer to a variable “p” which was not defined on the component class. As soon as I add a
p = 1;
property to the class, everything builds without error.@Pinank I just tested this:
ngx-pagination
(v3.0.0)NgxPaginationModule
and used the pipe and component in the app component.ng build --prod
andng build --aot --prod
and both of them completed without error.If you can tell me how to reproduce the error that you see, I’ll investigate.