Note this answer applies to the Material Design Icons by Templarian and NOT the icons of the same name by Google. I don't understand why these instructions aren't in the Readme, but here you go.
First, install the package:
npm install @mdi/font --save
Then, it is necessary to add the stylesheet to your styles.scss
file. I added the following to the end of my file:
//---------------------------------------------------------------------------
// Material Design Icons (https://materialdesignicons.com/)
//---------------------------------------------------------------------------
$mdi-font-path: "~@mdi/font/fonts";
@import "~@mdi/font/scss/materialdesignicons.scss";
Note the $mdi-font-path
is necessary to override a default set within the @mdi/font/scss/_variables.scss
which causes the webpack compiler to complain. If you forget to do this, you will get a series of errors, as follows:
ERROR in
./node_modules/css-loader!./node_modules/postcss-loader/lib??ref--3-2!./node_modules/sass-loader/lib/loader.js!./src/styles.scss
Module not found: Error: Can't resolve
'../fonts/materialdesignicons-webfont.eot' in
'/home/myRepo/myApp'
Edit: I'm not sure if this is necessary (it probably is in some cases), but I also updated the .angular-cli.json
file styles
element:
"styles": [
"../node_modules/@mdi/icon/font/css/materialdesignicons.min.css",
Another alternative to the above, which resulted in the icons working with very little effort, was to import the CSS directly. In the typescript file, I replaced the styleUrls
element (to avoid a strange bug with Karma):
// styleUrls: ['./graphics-control.component.css'],
styles: [require('./my.component.css'),
require('../pathTo/node_modules/@mdi/font/css/materialdesignicons.min.css')]