原语的JavaScript赋值不相等

原语的JavaScript赋值不相等,javascript,angularjs,Javascript,Angularjs,我使用ng类(来自angularjs)为分页表中的活动页码分配一个类。当按下“跳过10页”按钮时,它将调用一个函数,并最终在此处结束: if (this.scope.currentPage <= this.scope.lastPage - this.scope.pageNumbersGroupSize) { this.scope.currentPage += this.scope.pageNumbersGroupSize; } else { while (this.scop

我使用ng类(来自angularjs)为分页表中的活动页码分配一个类。当按下“跳过10页”按钮时,它将调用一个函数,并最终在此处结束:

if (this.scope.currentPage <= this.scope.lastPage - this.scope.pageNumbersGroupSize) {
    this.scope.currentPage += this.scope.pageNumbersGroupSize;
} else {
    while (this.scope.currentPage < this.scope.lastPage) {
        this.scope.currentPage++;
    }
    //this.scope.currentPage = this.scope.lastPage;
}
但由于某些原因,它没有激活我的HTML中的类:

<a ng-class="{'selectedPage' : pageNumber === currentPage, 'grayText' :
pageNumber !== currentPage}" ng-repeat="pageNumber in pageNumbers"
style="margin-right: 4px; cursor: pointer;" ng-click="goToPage(pageNumber)">
{{pageNumber}}
</a>

这仍然不起作用。因此,我尝试了while循环,它现在位于代码的顶部。这确实有效。有人能解释为什么我的原始代码不起作用吗?还有,有没有比把while循环放进去更好的方法来解决这个问题?谢谢大家!

弄明白了:这是因为我使用了a===而不是a==并且我用于lastPage的变量是作为字符串而不是数字从数据库存储过程返回的。它将字符串与===的数字进行比较,但它们不相等。我刚刚对DB返回的值使用了parseInt(),它是固定的。

所有这些都是固定的。在您的代码中,您是否使用ControllerAs语法引用了Ctrl?不,我正在使用typescript并将所有函数都放在构造函数之外。
<a ng-class="{'selectedPage' : pageNumber === currentPage, 'grayText' :
pageNumber !== currentPage}" ng-repeat="pageNumber in pageNumbers"
style="margin-right: 4px; cursor: pointer;" ng-click="goToPage(pageNumber)">
{{pageNumber}}
</a>
this.scope.currentPage = angular.copy(this.scope.lastPage);