Adding new fonts to an Angular 2 web page

I am working on an Angular 2 application and I want to incorporate wrapbootstrap. However, I am facing an issue with the fonts (bootstrap, font-awesome, google) and I am not sure how to include them.

While using the css file for wrapbootstrap, I am getting an error that it cannot locate font awesome:

"Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8000/fonts/font-awesome/fontawesome-webfont.woff2?v=4.4.0"

I am confused because I can actually see the missing file(s) in the resources in the Chrome console at that exact location.

https://i.sstatic.net/PKUhZ.png

The font files are currently located in a folder with the following relative path from the css (application.css) file:

https://i.sstatic.net/9AD8z.png

This path matches what is required in the css file:

https://i.sstatic.net/v9vs5.png

I hope someone can offer guidance as I am feeling lost.

Thank you in advance

Solved It turns out that the issue was related to the location of my fonts folder. My file structure is as follows: https://i.sstatic.net/HJJvy.png

I initially added the fonts/ directory relative to where the application.css file was. It needed to be placed in the root of my app (src)

Answer №1

Including fonts from a package manager can be a complex task at times. One common scenario is when you need to use font-awesome or a similar library.

To achieve this, follow these steps:

  1. In tools/config/project.config.ts:

    ...
        export class ProjectConfig extends SeedConfig {
            PROJECT_TASKS_DIR = join(process.cwd(), this.TOOLS_DIR, 'tasks', 'project');
    
            FONTS_DEST = `${this.APP_DEST}/fonts`;
            FONTS_SRC = [
                'node_modules/bootstrap/dist/fonts/**'
            ];
    ...
    
  2. Create a file

    tools/tasks/project/build.fonts.ts
    :

    import * as gulp from 'gulp';
    import Config from '../../config';
    
    export = () => {
      return gulp.src(Config.FONTS_SRC)
            .pipe(gulp.dest(Config.FONTS_DEST));
    };
    
  3. In gulpfile.ts (or in seed.tasks.json for newer versions of the Seed)

    // Build dev.
    gulp.task('build.dev', done =>
      runSequence('clean.dev',
                  'tslint',
                  'build.assets.dev',
                  'build.fonts',    // Added task;
                  'build.js.dev',
                  'build.index.dev',
                  done));
    // Build prod.
    gulp.task('build.prod', done =>
      runSequence('clean.prod',
                  'tslint',
                  'build.assets.prod',
                  'build.fonts',    // Added task;
                  'build.html_css.prod',
                  'build.js.prod',
                  'build.bundles',
                  'build.bundles.app',
                  'build.index.prod',
                  done));
    // Build test.
    gulp.task('build.test', done =>
      runSequence('clean.dev',
                  'tslint',
                  'build.assets.dev',
                  'build.fonts',    // Added task;
                  'build.js.test',
                  'build.index.dev',
                  done)); 
    

src

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ngFor dynamically updates on its own

Here is a sample code snippet from the list-components: list.components.ts import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal'; import { EditModalComponent } from "...../edit-modal.component"; @Component({ selector: 'list& ...

Adding CSS classes through the .addClass method - A guide on utilizing linked CSS files

I came across this code snippet and I have a quick question. $(window).scroll(function() { var y_scroll_pos = window.pageYOffset; var scroll_pos_test = 150; // adjust as needed if(y_scroll_pos > scroll_pos_test) { $( "#cssmenu" ).addCl ...

You need to click the form submit image twice in order to make it work

Struggling to get a standard opt-in form to work with an image submit button. The script works fine with a regular submit button, but the image button requires two clicks initially and then one click after unless the page is refreshed. I believe there mig ...

The dynamic addition of the active class is malfunctioning

I have dynamically added a class using AngularJS, but it seems to not be functioning correctly. As I am new to AngularJS, I would appreciate any suggestions to resolve this issue. Below is my HTML code: <div class="col-md-15 col-sm-3" ng-repeat="data i ...

Substitute commas with spaces in the material chips

I am using the material angular chips input. Here is how I am displaying the data: <div [ngStyle]="{'font-size':'18px'}" *ngFor="let ppsToDisplay of ppssToDisplay | async"> <mat-list *ngIf="ppsToDisplay.effetsind" > ...

Angular 2 Typeface Delivery to the Server

I'm experiencing an issue with the font when trying to access it from the server. It works fine on localhost, but on the server with a different directory structure, it fails to load properly. The same problem occurs with the logo as well. @font-face ...

Personalize the controls for spinning arrows

I am interested in learning how to personalize the appearance of the arrows on a spin box. input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: inner-spin-button !important; opac ...

Does this extensive combination of pseudo classes hold true?

Here's the code snippet I am working with: .fontmenu .fontlist{ position: absolute; bottom:30px; display:none; } .fontbutton button:hover .fontmenu .fontlist{ display:block; } <div class="fontmenu"> ...

Interact with the :before pseudo element when hovering over an element

Is there a way to manipulate the :before pseudo element when hovering over the main element? My goal is for the pseudo element to change its height when I hover over the main element. This is how my code looks: HTML <div class="object">& ...

Display the image on the right side when a specific number of pixels are available

Looking to have text wrapped around an image? Using float:right; can do the trick. However, is it possible to only float the image to the right when there is more than 200px of space available? For example: _____ |img | | | |_ ...

Animating an image inside a bordered div

I'm attempting to create an animated effect where an image moves randomly within the boundaries of a div container. While I've come across solutions for animating within borders, none have specifically addressed keeping the image inside the div. ...

Creating a Docker image for an Angular application with Node.js

Currently, I am attempting to develop an Angular application within a Docker environment and then run it as a container locally using Node.js. I have utilized the following Dockerfile to build the image, however, I am unsure of what might be missing when ...

Ways to make the Select component in Material-UI lose its focus state once an item has been selected

Anticipated outcome: Upon selecting an item, the Menu list will promptly close, and the Select component will no longer display a focus state. The borderBottom will change to 1px solid, and the backgroundColor will turn to white. Current situation: Sele ...

Adjusting the arrow direction upon clicking in a Select option

Is there a way to make the arrow move upwards when I open the select dropdown option? <select class="form-select" aria-label="Default select example"> <option selected>Choose an option</option> <option value="1">One</optio ...

Tips for making a slide-in animation that doesn't require adjusting the browser size

As I work on an animation where an img object and text slide in from outside the frame of the webpage upon page load, everything seems to be running smoothly. But there's one glaring issue: right at the start of the page load, the webpage resizes for ...

Is it possible to swap out a webpage link for a different one based on the size of the screen?

I designed a website for a friend: www.donjas-wellbeingforkids.co.uk I set up a Facebook Messenger Contact Us Link directly from the contact page here: donjaswell-beingforkids contact It's functional on desktop, where it seamlessly opens Facebook Me ...

Angular 8 bug: Requiring 2-3 arguments, received only 1

Currently deepening my knowledge in Angular and I encountered a situation within one of my services agree(id: string) { const headers = new HttpHeaders('Content-Type: application/json'); return this.HttpClient.put(`${this.apiUrl}/agree/` ...

Utilizing CSS to place an image on top of the upcoming <div> container

My goal is to create a layout similar to the one displayed in the linked image. https://i.stack.imgur.com/7DSE9.jpg Currently, I am using Bootstrap 3 and my HTML markup looks like this: <body class="gray-bg"> <section class="white-bg"> <d ...

Errors during compilation in Angular 2 local storage due to the absence of an exported member

Hello, I could use some assistance. I'm currently working on enabling local storage access in Angular 2 with typescript. To achieve this, I've integrated the npm package angular2-localstorage into my project. Initially, I had the "Tour of Heroes" ...

Create a tic tac toe game board using CSS styling for a table

I am considering creating a tic-tac-toe game using jQuery and PHP. I would like to customize the design of the game board, which is represented by an HTML table, by applying CSS styling. However, I am struggling to find CSS properties that would allow me t ...