angular dynamic style change code example
Example 1: add css dynamically in angular 6
import { CssService} from './Css.service';
@Component({
selector: 'DynamicCss',
templateUrl: './DynamicCss.component.html',
styleUrls: ['./DynamicCss.component.scss']
})
export class ServiceProviderComponent implements OnInit {
cssVariables: any;
constructor(private cssService:CssService){
/* call the service/api to get the css variable values in cssVariables */
}
}
Example 2: add css dynamically in angular 6
ngOnInit(){
this.appendCss(this.customizeFormData);
}