My target is to set or remove class depending on component boolean with Angular 2. For example: isRed = true > add class "red", if isRed = false > remove class "red". How is that possible? Code tried:
isRed: boolean;
constructor() {
$(document).scroll(function(){
var scrollTop = $(this).scrollTop();
if(window.location.hash) {
} else{
this.isRed = true;
}
if(scrollTop > 50) {
this.isRed = true;
}
else {
this.isRed = false;
}
});
}
and html:
[ngClass]="{red: isRed}"
isRed
might be always undefined.