我正在關注如何在angular 2中實現ng2-pagination的文檔。以下是我的代碼。但是,我陷入了在我的終端中出現的一些錯誤。我可能做錯了什麼?我的角度的版本是2.3.0Ang2中的ng2-pagination 2
table.html
<tr>
<th>Country</th>
<th>Continent</th>
</tr>
<tbody>
<tr *ngFor="let key of Country | keys | paginate: {itemsPerPage: 10 , currentPage: page}; let i = index" >
<td>{{i + 1}}</td>
<td>{{Country[key].name}}</td>
<td>{{Country[key].continent}}</td>
</tr>
</tbody>
</table>
<div class="has-text-centered">
<pagination-controls (pageChange)="page = $event"></pagination-controls>
</div>
部件
Component({
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CountryComponent {
@Input('data') Country:string[] =[];
page: number = 1;
//store incoming data
Country: Country[] = [];
constructor(private httpService: HttpService, private router: Router) {
this.httpService.getCountry()
.subscribe(data => {
this.Country = data;
}
);
}
錯誤
Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngForPaginate' since it isn't a known property of 'tr'. ("
<tbody>
<tr [ERROR ->]*ngFor="let key of Country | keys paginate: {itemsPerPage: 10 , currentPage: page}; let i = index" >"): [email protected]:8
Property binding ngForPaginate not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
也許它是,它並不像'keys'管在那裏?嘗試使用一些不需要該管道的虛擬數據並查看是否有效。我使用了相同的分頁,我真的沒有看到任何其他明顯的會導致該錯誤?這只是一個瘋狂的猜測,值得一試,但我並沒有真正明白爲什麼這會很重要,但是...... – Alex
沒有鑰匙,它可以和應用程序完美配合 – XamarinDevil
那麼......顯然它不起作用與另一個管道存在,這當然不好。而你的鑰匙管工作應該沒有分頁?如果情況是這樣的話,可能會在github項目中提出問題?我不認爲任何人都可以真正幫忙,如果是因爲'keys'管道,它不能正常工作......你需要嘗試另一個軟件包或更改'Country'來不需要管道...不支持muvch更多我可以說,對不起:( – Alex