How do I set StyleUrls with variable in Angular 2 -


i have ts file this

export const environment = {   production: false,   profile : './test/test.css' }; 

i import environment.profile , set can use in styleurls like

import { component, oninit } '@angular/core'; import { translateservice } "@ngx-translate/core"; import {environment} "../../environments/environment";  @component({   selector: 'app-header',   templateurl: './header.component.html',   styleurls: [environment.profile] }) 

but getting error:

error: cannot find module "." main.bundle.js:250:62 webpackmissingmodule http://localhost:4200/main.bundle.js:250:62 ../../../../../src/app/header/header.component.ts http://localhost:4200/main.bundle.js:250:29 webpack_require http://localhost:4200/inline.bundle.js:55:12 ../../../../../src/app/app.module.ts http://localhost:4200/main.bundle.js:71:83 webpack_require http://localhost:4200/inline.bundle.js:55:12 ../../../../../src/main.ts http://localhost:4200/main.bundle.js:291:74 webpack_require http://localhost:4200/inline.bundle.js:55:12 [2] http://localhost:4200/main.bundle.js:309:18 webpack_require http://localhost:4200/inline.bundle.js:55:12 webpackjsonpcallback http://localhost:4200/inline.bundle.js:26:23 http://localhost:4200/main.bundle.js:1:1 [wds] warnings while compiling. vendor.bundle.js:13428:10 ./src/app/header/header.component.ts 32:17-45 critical dependency: request of dependency expression vendor.bundle.js:13493:4

i don't know how fix can me

its because of value of variable environment.profile.

please see whether refers exact path of css or give path of styleurl string.

please correct me if have misinterpreted question.

---------------------update--------------------

according discussion in comments, suggest use approach based on class , not const.

because const doesn't return when called in constructor of component , return correct value in ngoninit().

https://www.youtube.com/watch?v=uq4klwpfosu

here video link new boston's tutorial of angular referred. there uses class named config store various details such main_heading etc..

so according me, cleaner approach solve problem.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -