Angular 2 getting object object while Class binding Angular 2 getting object object while Class binding angularjs angularjs

Angular 2 getting object object while Class binding


This is only because you use an Array at

[ngClass]="{'active': pagItem.pageNo === currentPage}"

However your code should works.

this has to be used when you have many possible class result like this :

[ngClass]="{'active': pagItem.pageNo === currentPage, 'inactive': pagItem.pageNo !== currentPage}"

You could also do this to avoid the [Object, Object] rendering,

[class.active]="pagItem.pageNo === currentPage"

Be sure that your variable currentPage is set in your component and shared the same type.


Try this and ensure pagItem.pageNo and currentPage are the same type.

    <ul class="pagination hidden-xs pull-right">    <li *ngFor="let pagItem of _pagination">        <a style="cursor: pointer;"            (click)="paginationClick($event)"            id="{{pagItem.pageNo}}"            [class.active]="pagItem.pageNo === currentPage">            {{pagItem.pageNo}}       </a>   </li></ul>