0
.element {
  background: url(env.asset-path)
}

What I want is to detect the env at the Angular side and define the asset path in CSS

I know that I could check server-name/domain with js but I don't know how to pass variables to css/scss files

I'm using Angular4/Typescript/scss

3
  • can you be more specific in your question? do you want to know if the environment is dev or prod? or do you want to know if the platform is browser or server? Oct 4, 2017 at 20:23
  • @FussinHussin I want to know if is dev or prod [y] Oct 4, 2017 at 20:56
  • I've found a better approach here in the second answer: stackoverflow.com/questions/42515893/… Oct 4, 2017 at 22:44

1 Answer 1

1

you can get your environment variable by importing it, the same way as your main.ts file:

import { enableProdMode } from '@angular/core';

myurl = environment.production

you cannot add these vars to your css files, but you can manipulate the dom, and add the background url by binding to the src attribute or doing an angular attribute binding. 1)

<img [src]="myurl">

2)

<div class="background"
     [ngStyle]="{ 'background-image': 'url(myurl)'}">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.