импорт ДОКУМЕНТА из угловых
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
name = 'Angular';
layout1;
layout;
layout3;
constructor(@Inject(DOCUMENT) private document: any) { }
addClass($event) {
if (this.document.body.classList) {
let className = Object['values'](this.document.body.classList).filter(d => d !== $event);
className.map(d => this.document.body.classList.remove(d));
this.document.body.classList.add($event);
}
else {
this.document.body.classList.add($event);
}
}
}
component.html
<form #f="ngForm">
<input type="radio" value="a" (ngModelChange)="addClass($event)"[ngModel]="layout1" name="1" ngModel>Layout 1<br>
<input type="radio" value="b"(ngModelChange)="addClass($event)" [ngModel]="Layout2" name="1" ngModel>Layout 2<br>
<input type="radio" value="c" (ngModelChange)="addClass($event)" [ngModel]="layout3" name="1" ngModel>Layout 3
</form>
Пример: https://stackblitz.com/edit/angular-7ffxib