I want to change the scope variable tab
to "home" every time the window size got changed. The following code does it well, but for some reason, the view doesn't get updated.
$scope.changeTab = function (tab) {
$scope.tab = tab;
};
angular.element($window).bind('resize', function () {
$scope.changeTab('home');
});
<div>{{ tab }}</div>
You should wrap your $scope.closeMoreTab();
into $scope.$apply
function, as this currently changes value, but doesn't trigger digest cycle:
angular.element($window).bind('resize', function() {
$scope.$apply(function() {
$scope.closeMoreTab();
});
});
您可以尝试将变量添加到$watch
,因为每当该变量的值发生变化时, $apply
将被调用,并且调用$apply
将处理$digest
循环。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.