V
V
Vitaly2016-12-18 12:17:24
css
Vitaly, 2016-12-18 12:17:24

How to write dynamic styles in Angular 2?

The idea is to have the styles depend on the js variables, but not overload the html with inline styles.
For example, we need a standard color around which the design of other components dances. In less we can put that color into a variable and then use some simple math to calculate the color deviation.

@main-color: #f00;
.smth {
  color: @main-color + #0f0;
}

But here comes the problem: to allow the user to spin the editing wheel for this color in real time. It turns out the problem is that the colors are compiled and built into css classes. Can styles and scripts interact in Angular 2 without deviating from writing css in the React style (description of styles in code)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2016-12-18
@vitali1995

less.js

A
Archer *range attack +10*, 2019-10-25
@kon-rafikov

Alternatively, you can override the value of the CSS variable with JS (see CSS custom properties)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question