How to use in Angular Material?

后端 未结 9 854
南方客
南方客 2021-01-29 19:39

I was wondering how to use Material\'s icons, as this is not working:

          


        
9条回答
  •  你的背包
    2021-01-29 19:49

    As the other answers didn't address my concern I decided to write my own answer.

    The path given in the icon attribute of the md-icon directive is the URL of a .png or .svg file lying somewhere in your static file directory. So you have to put the right path of that file in the icon attribute. p.s put the file in the right directory so that your server could serve it.

    Remember md-icon is not like bootstrap icons. Currently they are merely a directive that shows a .svg file.

    Update

    Angular material design has changed a lot since this question was posted.

    Now there are several ways to use md-icon

    The first way is to use SVG icons.

    Example:

    or

    :where getMyIcon is a method defined in $scope.

    or

    to use this you have to the $mdIconProvider service to configure your application with svg iconsets.

    angular.module('appSvgIconSets', ['ngMaterial'])  
      .controller('DemoCtrl', function($scope) {})  
      .config(function($mdIconProvider) {
        $mdIconProvider
          .iconSet('social', 'img/icons/sets/social-icons.svg', 24)
          .defaultIconSet('img/icons/sets/core-icons.svg', 24);    
      });
    

    The second way is to use font icons.

    prior to doing this you have to load the font library like this..

    or use font icons with ligatures

    face

    #xE87C;

    face

    For further details check our

    Angular Material mdIcon Directive documentation

    $mdIcon Service Documentation

    $mdIconProvider Service Documentation

提交回复
热议问题