I am trying to use bootstrap glyphicons in my angular2 app. I have installed bootstrap using the command npm install bootstrap --save My code snippet is
<button *ngIf="pos.name == uname" type="button" class="btn btn-default btn-sm delete" (click)="DeleteBulletin();">
<span class="glyphicon glyphicon-trash glyph"></span> Delete
</button>
I have included bootstrap in my styleUrls- styleUrls: ['node_modules/bootstrap/dist/css/bootstrap.min.css', 'app/home.component.css']
I installed bootstrap3 as npm install bootstrap@3 and it started working
just need to add in angular-cli.json:-
Please run
and than please import glyphicons in your component
You can check once in your browser console.
There is angular-cli-build.js file of root of the project if your application has been scaffold by angular-cli (using 'ng init' or 'ng new').
angular-cli-build.js instructs build of the project (using 'ng serve' or 'ng build') to place 3rd-party libraries into vendor folder.
There is fonts folder, in bootstrap distribution folder, holding glyphicons files. Those bootstrap files needs to be placed into vendor folder too.
angular-cli-build.js:
For completeness, setup process for bootstrap was in those few steps below:
Commnad line:
index.html:
Restart 'ng serve' or just rebuild with 'ng build'
Here is result of page source:
if you include bootstrap files through styleUrls this will make an issue, I don't know why, but I found that the borwser looks at different location for glyphicons.
using above method for calling bootstrap stylesheet file causes following error "GET http://localhost:4200/fonts/glyphicons-halflings-regular.woff "
what you can see from the error is that the browser is looking at
localhost:4200/fonts/...
where it should belocalhost:4200/vendor/bootstrap/dist/fonts/...
anyway, a workaround is to make sure that you added the
dist
folder of bootstrap insideangular-cli-build.js
file invendorNpmFiles
array as'bootstrap/dist/**/*.+(js|css|eot|ttf|woff|woff2)'
and remove bootstrap stylesheet fromstyleUrls
.then add to the index.html the following line:
dont forget to
ng serve
orng build
Boostrap 4 does not support Glyphicons anymore, you can use Font Awesome instead:
and add the css File to your .angular-cli.json
Replace CSS class with the Font Awesome classes:
recompile app:
ng serve
You have to import
<link data-require="bootstrap-css@3.3.6" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
to your index.html