AngularJs - the ng-class directive is not working

0

I'm trying to apply this class to this when I roll the page to fix my menu at the top of the screen, but the class is not being set:

<div class="page-header-menu" ng-class="{'fixed':(document.documentElement.scrollTop > 74)}">
    <!-- aplicação-->
</div>

I'm using version 1.2.30. My thanks to whom to respond.

    
asked by anonymous 22.09.2016 / 22:46

1 answer

0

It is not a good practice to access document directly within an angular component, but to solve your problem follow the code example below.

angular.module('app', []).controller('ctrl', function($scope) {
  $scope.a = 'aaa';
  $scope.fixElement = function(){
    return document.documentElement.scrollTop > 74
  }
})
.fixed {
  position: fixed;
  top: 100px;
  color: red;
 }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="app" ng-controller="ctrl">
  <div ng-class="{'fixed': fixElement()}">{{a}}</div>
</div>
    
22.09.2016 / 23:29