【发布时间】:2016-08-03 14:00:53
【问题描述】:
我有一个功能,当我将屏幕缩小到某个尺寸以下并单击表格行时,它会显示该表格行中的其他项目。 (左侧的白屏)。
然后,当我展开窗口时,我希望所有表格行恢复正常,但我有一个错误,如果它已经打开,它不会关闭。
我尝试将 $scope.showIt 变量设置为 true/false,但它似乎只有与初始 $scope.showIt 值相反时才会产生效果。当屏幕为一定大小时,如何更改每个 td 中的所有 ng-classes?
这是我的html:
<tr class="table-body "ng-repeat="service in services | orderBy:myOrderBy | filter:search">
<td align="center" valign="middle" ng-click="showIt = dropDetails(showIt)" ng-class="{'name-show':showIt, 'name-show-disabled':!showIt}">{{ service.name }}</td>
<td ng-class="{'show':showIt, 'show-disabled':!showIt}">{{ service.description }}</td>
<td ng-class="{'show':showIt, 'show-disabled':!showIt}">{{ service.prices }}</td>
</tr>
在我的控制器中:
$scope.dropDetails = function(showIt){ //This function works well.
console.log(window)
console.log(window.innerWidth)
if(window.innerWidth < 760){
return !showIt;
}else{
return showIt;
}
}
var w = angular.element($window);
var resizeId=0;
$scope.showIt = true;
w.bind('resize ', function (a) {
clearTimeout(resizeId);
resizeId = setTimeout(function(){
if(w[0].innerWidth < 760){
}else{
$scope.showIt = true; //Does nothing.
$scope.$apply();
}
}, 500);
})
【问题讨论】:
-
您从未将
$scope.showIt设置为false。是错字吗? -
@AdnanUmer
dropDetails函数在 ng-click 时将其设置为 false -
if(window.innerWidth < 760){ return !showIt; } -
窗口再次变大后如何重新设置变量“w”?
-
w[0].innerWidth准确调整窗口大小。