Angular字体很棒的图标不渲染(现场尝试了其他建议)

发布于 2025-01-22 23:13:58 字数 3105 浏览 2 评论 0 原文

我正在尝试将删除图标添加到我的角度任务列表项目中。我使用了 ng添加 @fortawesome/angular-fontawesome 。然后,我在故障排除时使用NPM安装。我遵循了其他线程之一的指南,并清除了缓存并重新启动了服务器。我已经多次检查了我的代码,但无法弄清楚这个问题。我没有错误消息。我的页面加载,但没有图标渲染。这是我的代码:

app.module.ts

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { FormsModule } from '@angular/forms'; // <-- NgModel lives here
    
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { TaskComponent } from './task/task.component';
    import { TasksComponent } from './tasks/tasks.component';
    import { TaskDetailComponent } from './task-detail/task-detail.component';
    import { DatesComponent } from './dates/dates.component';
    import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
    import { ButtonComponent } from './components/button/button.component';
    
    @NgModule({
      declarations: [
        AppComponent,
        TaskComponent,
        TasksComponent,
        TaskDetailComponent,
        DatesComponent,
        ButtonComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        AppRoutingModule,
        FontAwesomeModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }`
    ````
    **app.component,html**
    ````
    <div class="content">
    <!--task section-->    
    <h1>{{ title }}</h1> 
    <!--stack overflow method-->
    <img src="/assets/images/victorian.jpg" alt="victorian house" width="450"     height="300">
    <app-tasks></app-tasks>
    
    <!-- icon assoc. with font awesome install-->
    <fa-icon [icon]="faTimes"></fa-icon>
    
    <!--due date section-->   
    <app-dates></app-dates>
    
    </div>

task-detail.component.ts


    import { Component, OnInit, Input } from '@angular/core';
    import { Task } from '../task';
    import { faTimes } from '@fortawesome/free-solid-svg-icons';
    
    @Component({
      selector: 'app-task-detail',
      templateUrl: './task-detail.component.html',
      styleUrls: ['./task-detail.component.css']
    })
    export class TaskDetailComponent implements OnInit {
      @Input() task?: Task;
      faTimes = faTimes;
    
      constructor() { }
    
      ngOnInit(): void {
      }
    
    }

task-detail.component.ponent.html

 

   <div class="flex-container">
            <div *ngIf="task">
   
       <h2>{{task.name | uppercase}} Details </h2>
       <div><span>id: </span>{{task.id}}  <fa-icon [icon]= "faTimes"></fa-icon></div>
       <div>
         <label for="task-name">Task name: </label>
         <input id="task-name" [(ngModel)]="task.name" placeholder="name">
       </div>
   
       </div>

非常感谢!

I am attempting to add a delete icon to my Angular task list project. I have used ng add @fortawesome/angular-fontawesome. I then used npm install later when troubleshooting. I followed the guidance on one of the other threads and I cleared my cache and restarted the server. I have checked my code numerous times and cannot figure out the issue. I have no error messages. My page loads but no icon renders. Here is my code:

app.module.ts

    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { FormsModule } from '@angular/forms'; // <-- NgModel lives here
    
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { TaskComponent } from './task/task.component';
    import { TasksComponent } from './tasks/tasks.component';
    import { TaskDetailComponent } from './task-detail/task-detail.component';
    import { DatesComponent } from './dates/dates.component';
    import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
    import { ButtonComponent } from './components/button/button.component';
    
    @NgModule({
      declarations: [
        AppComponent,
        TaskComponent,
        TasksComponent,
        TaskDetailComponent,
        DatesComponent,
        ButtonComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        AppRoutingModule,
        FontAwesomeModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }`
    ````
    **app.component,html**
    ````
    <div class="content">
    <!--task section-->    
    <h1>{{ title }}</h1> 
    <!--stack overflow method-->
    <img src="/assets/images/victorian.jpg" alt="victorian house" width="450"     height="300">
    <app-tasks></app-tasks>
    
    <!-- icon assoc. with font awesome install-->
    <fa-icon [icon]="faTimes"></fa-icon>
    
    <!--due date section-->   
    <app-dates></app-dates>
    
    </div>

task-detail.component.ts


    import { Component, OnInit, Input } from '@angular/core';
    import { Task } from '../task';
    import { faTimes } from '@fortawesome/free-solid-svg-icons';
    
    @Component({
      selector: 'app-task-detail',
      templateUrl: './task-detail.component.html',
      styleUrls: ['./task-detail.component.css']
    })
    export class TaskDetailComponent implements OnInit {
      @Input() task?: Task;
      faTimes = faTimes;
    
      constructor() { }
    
      ngOnInit(): void {
      }
    
    }

task-detail.component.html

 

   <div class="flex-container">
            <div *ngIf="task">
   
       <h2>{{task.name | uppercase}} Details </h2>
       <div><span>id: </span>{{task.id}}  <fa-icon [icon]= "faTimes"></fa-icon></div>
       <div>
         <label for="task-name">Task name: </label>
         <input id="task-name" [(ngModel)]="task.name" placeholder="name">
       </div>
   
       </div>

Thanks so much!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染年凉城似染瑾 2025-01-29 23:13:58

检查fontawesome兼容性表并安装特定版本。

兼容表urls-

  1. https://www.npmjs.com/package/@fortawesome/angular-fontawesome

运行命令 -

npm install @fortawesome/angular-fontawesome@<version>

例如,我的角度项目版本是13。 -cfemail =“ 2D4C434A58414C5F004B4243594C5A485E4240486D1D1D031C1D0355”> [email&nbsp; proceeded]

Check the Fontawesome compatibility table and install specific version.

Compatibility table URLs -

  1. https://www.npmjs.com/package/@fortawesome/angular-fontawesome
  2. https://github.com/FortAwesome/angular-fontawesome

Run command -

npm install @fortawesome/angular-fontawesome@<version>

For example, my angular project version is 13. So I have used this fontawesome version npm install @fortawesome/[email protected]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文