In my older AngularJS app, we made a directive to add and remove a class to an element based on scroll position:
(function () {
'use strict';
angular.module('pb.ds.components').directive('pbdsHeaderShadow', function ($window) {
return {
restrict: 'AE',
link: function postLink (scope, element) {
angular.element($window).on('scroll', function () {
if (this.pageYOffset > 20) {
element.addClass('shadow');
} else {
element.removeClass('shadow');
}
});
}
};
});
})();
What's the Angular (6) way to create this same directive?