There are many ways to use the MaterializeCSS environment.
A few things to keep in mind before proceeding with the installation.
- This is not a CSS framework, although it does have a CSS name. We can also use it SCSS
- It is not built for Angular
- This is a component structure too built into jquery. Although we should not use jquery (not recommended) in angular, we still import.
You can use any of the following methods:
- Cdn
- Assets
- Include in Angular (NPM)
Each has its own advantages and disadvantages.
Cdn
Just add this to index.html and you're good to go.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css"> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script>
Assets
Add it as an asset to your project. This helps the Internet-independent when creating and working locally.
Download jQuery
Download CSS Version
Include in Angular (NPM)
In this method, we directly include files in our Angular construct. I assume the Angular project is built with @angular/cli for simplicity.
Do
npm install materialize-css --save npm install jquery --save npm install url-loader --save
Add the .angular-cli.json to .angular-cli.json :
"styles": [ "styles.scss" ] "scripts":[ "../node_modules/jquery/dist/jquery.js", "../node_modules/materialize-css/dist/js/materialize.js" ]
Inside styles.scss add the following:
$roboto-font-path: "~materialize-css/dist/fonts/roboto/"; @import "~materialize-css/sass/materialize";
Integration with Angular:
All the installation methods described above provide full functionality with materialization and do not require further installation of any work to work in Angular . Take any example and just use the appropriate HTML structure inside the HTML part of Angular components, and you're good to go.
In some cases, you may need to use javascript, and for this we need to use jQuery. Instead, we can use the Angular shell developer in angular2-materialize . I developed a full functional site using Angular, and I materialize and never felt the need for it.
If you still think you need it. You can set the following:
- Install materialization using any of the following methods.
Install angular2 -materialize
npm install angular2-materilize
Add to Angular app.module.ts
import { MaterializeModule } from "angular2-materialize"; @NgModule({ imports: [ //... MaterializeModule, ], //... })
Follow the other examples on the angular2-materialize homepage