How do I get a css property and not a class in Angular2?
I have the following code:
app.component.ts:
import { Component, HostBinding } from '@angular/core';
@Component({
selector: 'body',
templateUrl: 'views/masterpage.html'
})
export class AppComponent {
@HostBinding('attr.class') hostClass = "sticky-header sidebar-open"; // Works, but not what i want
@HostBinding('style.position') hostPosition:string; // Does not work
sidebarToggle() {
this.sidebarCollapsed = !this.sidebarCollapsed;
this.hostClass = (this.sidebarCollapsed ? "sidebar-collapsed" : "sticky-header sidebar-open");
// Here I wanna check what is the 'position' property of my host (body).
// See "style-responsive.css"
}
}
style-responsive.css:
@media screen and (max-width: 1024px) {
body {
position: relative;
}
}
So, as you can see, the page will add the position relative to the body whenever the user shrinks the window.
I just wanna get this information in my Angular component. hostPosition should be undefined if window is larger than 1024px and 'relative' if smaller than that.
How to achieve that?