2016-10-02 83 views
0

我正在使用最新的ng2-pagination(0.4.1)和angular2-webpack-starter(5.0.5)。不能使用ng2-pagination with angular2-webpack-starter

我的目標是嘗試ng2-pagination

我遵循以下步驟:

  • 使用npm install ng2-pagination --save;
  • 加入import 'ng2-pagination'vendor.browser.tsng2-pagination安裝;
  • 新增import {Ng2PaginationModule} from 'ng2-pagination';app.module.ts,然後將Ng2PaginationModule加到它的進口數組中;

  • 改變detail.component.ts像這樣:

    import { Component } from '@angular/core'; 
    @Component({ 
    selector: 'detail', 
    template: ` 
        <h1>Hello from Detail</h1> 
        <ul> 
        <li *ngFor="let item of collection | paginate: { itemsPerPage: 10, currentPage: p }">{{ item }}</li> 
        </ul> 
        <pagination-controls (pageChange)="p = $event" #api> 
        </pagination-controls>` 
    }) 
    export class Detail { 
    collection = []; 
    constructor() { 
        for (let i = 1; i <= 100; i++) { 
        this.collection.push(`item ${i}`); 
        } 
        } 
    } 
    

我得到以下錯誤:

EXCEPTION: Uncaught (in promise): Error: Template parse errors: 
The pipe 'paginate' could not be found 

It seems to me that the component doesn't know about ng2-paginate: what am I missing?

回答

1

OK,我固定它:

失誤正在第三步;代替:

  • import {Ng2PaginationModule} from 'ng2-pagination';app.module.ts,然後添加到Ng2PaginationModule其進口陣列;

我應該做到以下幾點:

  • import {Ng2PaginationModule} from 'ng2-pagination';./+detail/index.ts,再加入Ng2PaginationModule其進口陣列;

猜猜我對最新的angular2不夠熟悉。希望這會幫助某人。