I was doing the research if it is possible to use the SCSS variable value in HTML or TS in Angular.
For example
I have a variable called $mdBreakpoint: 992px;
inside _variable.scss file
In html I have a condition
[ngClass]="{'col-sm-3': innerWidth >= 992}"
992 is the same value as the $mdBreakpoint
My question is it possible to refer $mdBreakpoint
in HTML condition.
I am using Angular 8
You can create a variable which holds value of mdBreakpoint
and then use it HTML template:
TypeScript:
mdBreakpoint = 992;
HTML:
[ngClass]="{'col-sm-3': innerWidth >= mdBreakpoint }"
It's not directly supported by Angular, html or sass. You can't access scss variables in a html template without writing some logic.
See this answer if you want more information on how to do it: access SASS values ($colors from variables.scss) in Typescript (Angular2 ionic2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.