I'm building an angular 2 app written in typescript. It would use the bootstrap 4 framework in combination with some custom theming, is this possible?
The "ng2-bootstrap" npm package is not working as it doesn't allow me to use the bootstrap css classes, instead it provides custom components. (http://github.com/valor-software/ng2-bootstrap)
In my angular 2 project I'm using sass, would it be possible to build bootstrap 4 from source as it is also using sass for styling?
ng add
has been introduced with Angular 6. To install Bootstrap 4 (ng-bootstrap 2.0.0)Don't forget to restart your app with
ng serve
.In angular 6 dont use npm i bootstrap@next --save may it would work but sometimes it would not better to add these:
Adding Bootstrap using Angular CLI:
This works fine with angular 7 scss enabled project
Run following commands for installing bootstrap, jQuery, and popper.js
jQuery, and popper.js are prerequisites for running bootstrap4 (refer https://getbootstrap.com for more information.)
Go to your angular.json file inside root folder. Edit
node as follows
This will enable javascript functions of bootstrap on your project.
Than go to
src->styles.scss
file and add following lineTo use any visual library that needs JQuery just do the following:
If the library doesn't have definition files you could:
Now you can use the library inside Typescript;
The options above will work, however I use this approach via NPM:
Run the NPM command obtained from step 1 in your project i.e
npm install bootstrap@4.0.0-alpha.5 --save
After installing the above dependency run the following npm command which will install the bootstrap module
npm install --save @ng-bootstrap/ng-bootstrap
You can read more about this hereimport {NgbModule} from '@ng-bootstrap/ng-bootstrap';
and addNgbModule
to theimports
Your app module will look like this:
Open angular-cli.json and insert a new entry into the styles array :
Open src/app/app.component.html and add
or if you would like to use ng alert then place the following on your
app.component.html page
Now run your project and you should see the bootstrap alert message in the browser.
NOTE: You can read more about ng Components here