2

So from Load external css style into Angular 2 Component it seems that including css from an external url by putting it into the styleUrls[] worked for angular 2. It does not work for Angular though (it just searches for the css sheet under the directory). I can't find any documentation regarding this so I'm just hard-coding it into the entire index.html page for now. How can I get it to work for individual components?

Edit: To clarify, by external css I mean something like this: https://www.w3schools.com/w3css/4/w3.css, not something included in my project.

2 Answers 2

7

I know it is a bit late answer, but if somebody looks for solution:
You can use command line if you use nodeJS in your app folder write:

npm install --save w3-css

You should adjust then angular-cli.json in your src folder of your app and where you register styles type following:

"styles": [
        "../node_modules/w3-css/w3.css",
        "styles.css"
      ],
Sign up to request clarification or add additional context in comments.

Comments

4

For including an external css (remote url)for an specific component. I've only found this way. For example for your app component.

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

in your app.component.scss you can import a remote url with the desired remote styles like this css file your were commenting.

@import url('https://www.w3schools.com/w3css/4/w3.css');

Even thought it is not a perfect solution, hope it helps.

2 Comments

Thanks for the response, but I was actually considering css from the web.
thanks for the clarification, I've done some research and I have updated my response.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.