Alan Alan - 1 year ago 44
HTML Question

only one of two css files is in effect in angular 2 app

I am following a tutorial on angular 2, and at some point i had to use bootstrap classes. In the external libraries folder, bootstrap exists but it didn't seem to work. To solve that i imported it in the

file, and although it now works, my other css file doesn't. These are the contents of
(css files in lines 6-7):

<title>Angular 2 QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="">
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
System.import('app').catch(function(err){ console.error(err); });
<!-- 3. Display the application -->

also here is the part where i use the bootstrap classes:

template: `
<i class="glyphicon"
[class.glyphicon-star] = "isFull"
[class.glyphicon-star-empty] = "!isFull"

and finally

h1 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-size: 250%;
body {
margin: 2em;

Answer Source

You must have heard about ViewEncapsulation metadata property of @Component. You can use it like this way for bootstrap to work with your custom style,

    selector: 'my-app',
    encapsulation: ViewEncapsulation.none,
    styleUrls:  ['style.css'],

Check working demo,