代码之家  ›  专栏  ›  技术社区  ›  Whisher

角度字体一些大小-无法绑定到“ngclass”,因为它不是“fa icon”的已知属性

  •  0
  • Whisher  · 技术社区  · 7 年前

    我正在寻找一种方法来调整组件的大小 使用fontAwesome库

    import { library } from '@fortawesome/fontawesome-svg-core';
    import {
      faBell
    } from '@fortawesome/free-solid-svg-icons';
    
    library.add(
      faBell
    );
    
    
    @Component({
      changeDetection: ChangeDetectionStrategy.OnPush,
      selector: 'iwdf-icon-bell',
      template: `<fa-icon [ngClass]="cls" [icon]="['fas', 'bell']"></fa-icon>`,
      styles: [`:host {
        display: inline-block;
      }`]
    })
    export class IconBellComponent{
      @Input() cls: string;
    }
    

    但我有个错误:

    Can't bind to 'ngClass' since it isn't a known property of 'fa-icon'.
    

    我知道我会作弊,比如:

    @组件({

      changeDetection: ChangeDetectionStrategy.OnPush,
      selector: 'iwdf-icon-bell',
      template: `<fa-icon class="{{cls}}" [icon]="['fas', 'bell']"></fa-icon>`,
      styles: [`:host {
        display: inline-block;
      }`]
    })
    export class IconBellComponent{
      @Input() cls: string;
    }
    

    但我想知道还有没有别的办法。

    知道吗?

    更新

    我是用以下方法计算出来的:

    @Component({
      changeDetection: ChangeDetectionStrategy.OnPush,
      selector: 'icon-angledown',
      template: `<fa-icon [className]="cls" [icon]="['fas', 'angle-down']"></fa-icon>`,
      styles: [`:host {
        display: inline-block;
      }`]
    })
    export class IconAngleDownComponent{
      @Input() cls: string = '';
    }
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   Danish Arora    7 年前

    尝试在ngmodule“导入”中添加browsermodule

    @NgModule( imports: [BrowserModule] )

    直接在ngclass中使用表达式

        2
  •  0
  •   Vaibhav    7 年前
    <i class="fa" [ngClass]="{'cls','fas-bell'}"></i>
    

    尝试在ngclass中移动fa图标类本身

    推荐文章