I am trying to toggle a class on an element if/when the page has scrolled.
I have followed this SO thread but when I try chaining in a directive, I don't even get to the log statements.
Trying to follow along with the angular docs, I've got my component.js file like this. I can get the log statements to show, but the class never gets toggled.
dashboard.component.js
angular.module('dashboard')
.component('dashboard', {
'templateUrl': 'dashboard/dashboard.template.html',
controller: function dashboardController($scope, $window, $mdSidenav) {
var primaryAppBar = angular.element(document.querySelector('#primaryAppBar'));
angular.element($window).bind('scroll', function () {
if (this.pageYOffset > 0) {
console.log('add shadow');
$scope.boolChangeClass = true;
} else {
console.log('remove shadow');
$scope.boolChangeClass = false;
}
});
...
app-bar.template.html
<md-toolbar id="primaryAppBar" ng-class="{'md-whiteframe-1dp':boolChangeClass}">
...