简体   繁体   中英

Angular-cli adding styles from external url

Is there way to load css styles from an external url?

For example, I have domain.eu but on my site in sub.domain.eu. I want to use styles which are stored in this domain. (These styles are common for all sites).

Example below is not working for sure.

"styles": [
    "styles.css",
    "http://domain.eu/themes/css/common.css"
  ],

Problem is that webpack is trying to bundle this styles. He cannot retrieve it. When I import it via css

@import('url');

It will not breakdown but it will have problem with missing assets like images or fonts.

Only solution is to add external css style into index.hml. But it is possible to set this value dynamically?

When we have three different themes which defines basic fonts, styles of headers and so on and I want to change it for example by route or basic select option element inside some component is there some kind of hack or something I can do it?

是的,您可以在 @Component 中使用像styleUrls: ['file name.css']这样的外部 css 添加样式

You are using

"styles": [ "styles.css", " http://domain.eu/themes/css/common.css "]

it is used to write direct css for the respective component but if you want to include some css from other files then you should use like this

styleUrls: [ 'styles.css', ' http://domain.eu/themes/css/common.css ' ]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM