Javascript 在AngularJS中,冒号后的double equal是什么意思
所以我从服务器端找到了这段关于分页的代码,除了它对这一部分的作用之外,我什么都懂,我知道控制器正在监视currentPage,但是没有活动变量,我不知道冒号后面的double equal是什么意思 html和角度控制器:Javascript 在AngularJS中,冒号后的double equal是什么意思,javascript,angularjs,Javascript,Angularjs,所以我从服务器端找到了这段关于分页的代码,除了它对这一部分的作用之外,我什么都懂,我知道控制器正在监视currentPage,但是没有活动变量,我不知道冒号后面的double equal是什么意思 html和角度控制器: app.controller(“myController”,函数($scope,Student){ $scope.studentsPerPage=5; $scope.currentPage=0; $scope.range=函数(){ var rangeSize=5; var-
app.controller(“myController”,函数($scope,Student){
$scope.studentsPerPage=5;
$scope.currentPage=0;
$scope.range=函数(){
var rangeSize=5;
var-ret=[];
var start=$scope.currentPage;
如果(开始>$scope.pageCount()-rangeSize){
start=$scope.pageCount()-rangeSize;
}
对于(变量i=开始;i 0){
$scope.currentPage--;
}
};
$scope.prevPageDisabled=函数(){
返回$scope.currentPage==0?“已禁用”:“”;
};
$scope.nextPage=函数(){
如果($scope.currentPage<$scope.pageCount()){
$scope.currentPage++;
}
};
$scope.nextPageDisabled=函数(){
返回$scope.currentPage>=($scope.pageCount()-1)?“已禁用”:“;
};
$scope.pageCount=函数(){
返回Math.ceil(Student.total()/$scope.studentsPerPage);
};
$scope.setPage=函数(n){
$scope.currentPage=n;
};
});代码>
您正在寻找的
求值结果可以是表示以空格分隔的类名的字符串、数组、或类名到布尔值的映射。对于映射,值为truthy的属性的名称将作为css类添加到元素中
如果表达式n==currentPage
为真,则将类active
添加到元素中。可以添加更多的类表达式对
data-ng-class="{active: n == currentPage, hidden: n == 0, answer: n == 42}"
我假设您对绑定数据ng class=“{active:n==currentPage}”
感到困惑?如果是这样,n
是循环中的当前索引,绑定是说如果n
等于currentPage
变量,则设置活动类。它用于将n
与currentPage
同步。下面是一个细分:
data ng repeat=“n in range()”
:让我循环查看range()中的值。对于每次迭代,我将用于引用当前循环值的变量将为n
data ng class=“{active:n==currentPage}”
:现在我想知道哪个是活动循环值。因此,我可以使用n
并与之同步currentPage
!。同时,。我还将使用active
类应用于n
您之所以要保持这种状态,是因为您的控制器中引用了currentPage
,{active:n==currentPage}
是一个具有活动属性的对象文字,其值是通过计算表达式n==currentPage
计算得出的布尔值(该表达式应使用==
,但这是另一个主题)。
data-ng-class="{active: n == currentPage, hidden: n == 0, answer: n == 42}"