Internet Explorer 11 fails to interpret the attribute attr.xlink:href

I am a beginner in Angular 2 and I'm working on creating an icon component. The code I have below works perfectly in Chrome and Firefox, but unfortunately, it's not functioning in Internet Explorer 11.

Here is what my component looks like:

@Component({
  selector: 'my-icon',
  template: `
    <svg *ngIf="_iconClass" class="icon" [ngClass]=_iconClass 
      xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <use xlink:href="" attr.xlink:href="#{{ _iconClass }}" />
    </svg>
  `
})
export class MyIcon {

  private _iconClass: string = '';
  @Input() set iconClass(i: string) {
    if ((i !== undefined) && (i.indexOf('.ico') > -1)) {
      // remove .ico from iconname
      this._iconClass = i.substr(0, i.length - 4);
    } else {
      this._iconClass = i;
    }
  }

Then, I'm using it in another component like this:

<my-icon iconClass="icon--user"></my-icon>

I haven't included all the code, but I hope you get the idea. When I checked in Developer tools, the <use xlink:href> tag is empty. I suspect that IE 11 may not recognize

attr.xlink:href="#{{ _iconClass }}"
.

I can't seem to figure out the issue. Any help would be greatly appreciated.

Edit:

This error message is displayed in the console

EXCEPTION: TypeError: Unable to get property 'contains' of undefined or null reference in [_iconClass in MyIcon@1:9]

private validateIcon(): void {
    if ((this._iconClass !== undefined) && (this._iconClass !== '') && (document.getElementById(this._iconClass) === null)) {
      if (this._validateIconRunOnce) {
        console.warn('Icon(' + this._iconClass + ') not found.');
        this._iconClass = 'not-found';
      } else {
        // delay validate icon for 3s to wait until the iconlibrary is loaded
        this._validateIconRunOnce = true;
        setTimeout(() => this.validateIcon(), 3000);
      }
    }
  }

Answer №1

Gunter

I really appreciate your help and guidance. I was able to find the perfect solution on this page: https://github.com/eligrey/classList.js

Adding classList.js is necessary to enable svg support in IE9 and above.

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

PHTML file IIS handler

I was surprised by the lack of online results when searching for a solution to my issue. In my local PHP project, I am encountering problems with PHTML files not being parsed correctly by IIS. The 'phtml' type is not included in the module mappin ...

What is the best way to trigger the download of an image file created by PHP to a user's computer?

My PHP code (upload.php) allows users to upload an image from index.html, resize it, add a watermark, and display it on the same page. Users can download the watermarked image by using the 'Save image as...' option. The resized image is saved in ...

Guidelines for Organizing Angular Interface Files and Implementing Custom Type Guards

In my Angular 2 project, I am utilizing Interfaces and have implemented User Defined Type Guards: grid-metadata.ts export interface GridMetadata { activity: string; createdAt: object; totalReps: number; updatedAt: object; } grid.service.ts ... ...

Displaying nested arrays correctly

My latest endeavour involves constructing a data tree in Vue, utilizing components. Let's examine the provided data snippet: "data": [ { "id": 1, "name": "foo", "children": [ { "id": 2, "name": "bar", "children": [] } ...

Having trouble compiling Angular CLI version 8.3.21 with the command ng serve

Upon trying to compile my first Angular app, I encountered an error when running ng serve: ERROR in ./src/styles.css (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded! ...

Instant access to an interactive online platform

Is it feasible to create a shortcut from a webpage to my desktop for quick access? For instance, if a dynamic web page has 15 documents and I want to easily create shortcuts to them on my desktop by clicking on each one. I understand this is a brief quest ...

Encountered a ZoneAwareError while trying to incorporate angular2-onsenui into

Have you run the following commands in your terminal: npm install angular2-onsenui@latest --save npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0bfbea3b5bea5b990e2fee2fea8">[email protected]</a> ...

Currently in the process of optimizing controllers but continuously encountering 404 errors when making api requests

I previously utilized the SampleData controller that is automatically generated. I added my custom methods, everything was functioning perfectly. Recently, I decided to create a new class for better organization purposes. After pasting in the desired metho ...

Horizontal scrolling overflow disrupts vertical overflow visibility

I am attempting to display a container containing input elements that receive a warning bubble positioned absolutely when the input is invalid. However, the issue I am facing is that the bubble does not extend beyond the boundaries of the container as anti ...

Incorporate text into the URL of the image

Got a URL of an image like this: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg', and looking to add 240x240 within the URL. Current Url: https://lipsum.mobi/catalog/product/SE0229E/YG/AAA/4/1/SE0229E-YG-AAA-4.jpg Desire ...

Generating a sequential array of dates and times in Angular

Currently, I am working on implementing a feature that will allow users to see the available visit times between two dates they select, specifically from 8:00 to 17:00 every day. For instance: If a user selects 1 Sep to 4 Sep, the system should return [1. ...

iOS Safari: Full-width header with fixed position exceeding viewport width

Encountered an issue specific to Safari on iOS. Creating a page with a fixed position header that spans the width of the viewport. The content consists of multiple images that should scroll horizontally while the header remains in place during scrolling. ...

Securing Angular CLI Assets: Implementing canActivate for Protection

I am facing an issue where anyone can access my website's assets using URLs like http://localhost:4200/assets/filename.pdf, even when the user is not logged in. How can I secure these assets by implementing a canActivate guard? An ideal solution woul ...

Replace the default disc icon with a more detailed icon for UL lists

I am working with an unordered list and I want to use <details> to show a sublist for one of the items: <ul> <li><details> <summary>details bullet</summary> <ul> <li>detail 1</li> ...

What is the best way to modify the text color in an MUI Text Field?

I'm completely new to using MUI and React, and I've run into an issue with changing the text color in my input field. Even though I specified inputProps={{sx: { color: "CCCCCC" }}}, the text color remains black while the label and searc ...

Can you please tell me the font size specified as 20px/26px?

Recently stumbled upon the 20px/26px value in a codebase I'm currently working on. Wondering if anyone has encountered this before and knows what its purpose is. Interestingly, it renders with the latter pixel value (26px) in Chrome. #action { font: ...

The Bootstrap-Select dropdown refuses to open

I've been attempting to create a menu using data-subtext, and while I have come across some suggestions on stackoverflow, I'm still having trouble getting the menu to function properly. The issue I'm facing is that the menu doesn't seem ...

Having trouble properly refreshing Bootstrap scrollspy that is spying on the <body> element

I've been looking at a post on Bootstrap's scrollspy component (found here). In my code, I initialize a new scrollspy to track the body element using: $("body").scrollspy({ offset: 25 }); As my code progresses, I make AJAX requests that add or ...

How about incorporating AJAX into your HTML code?

I am currently in the process of developing an email system for a company that wishes to use it for sending emails. To achieve this, I have implemented a custom HTML editor for creating email content. My goal is to post the email contents to an external PH ...

`The font appears extremely thin when viewed on Safari and iOS devices.`

I'm struggling to resolve the issue with super-thin fonts on Safari/iOS despite trying all recommended solutions. Here is the comparison: https://i.stack.imgur.com/5DVHz.png The _document.js file: import Document, { Html, Head, Main, NextScript } fr ...