Angular 2.x bind class on body tag

Solution 1:

Using <body> as app component works fine but you can't use binding on the <body> tag because it attempts to bind `"isFixed" to the parent and there is no parent.

Use @HostBinding instead

@Component(
  selector: 'body',
  templateUrl: 'app_element.html'
)
class AppElement {
  @HostBinding('class.fixed') 
  bool isFixed = true;
}

This is Dart code but it shouldn't be hard to translate it to TS.

See also @HostBinding and @HostListener: what do they do and what are they for?

You can always use plain JS to update the DOM if you don't depend on server side rendering or web workers.

Alternatively you can just use

document.body.classList.add('foo');