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

Troubleshooting Problems with Image Width in CSS Styles

I am facing an issue with displaying 3 images in a row side by side. The first image is bigger than the other two, causing them to be pushed down to the next row, which is not what I want. I have created a class and specified the height and width, but it d ...

What is the best way to center align two inner divs within a container?

I've been working on achieving the following design: https://i.sstatic.net/ckC3j.png Just to clarify, the dashed line represents a guide indicating that both .inner-a and .inner-b are aligned in the middle horizontally and vertically within the imag ...

Formatting your HTML tags in Visual Studio

For instance, I have this particular tag with concise content <div>It is brief</div> However, upon formatting, Visual Web Developer presents it as <div> It is brief</div> which is unattractive. What I desire is <div> ...

When retrieving data from MongoDB, an error occurs stating "Unable to read the property 'firstname' of null."

I've been working on retrieving user information from MongoDB and displaying it through HTML, but I keep encountering an error that says: "Cannot read property 'firstname' of null." For my backend service, I'm using Express and Node.js, ...

The daterangepicker reigns supreme above all other elements

Just a heads up, I am utilizing daterangepicker from this link: . Recently, I encountered an issue where the input field was overlapping with other elements like bootstrap Modals or menus. <div class="col-md-3 form-group"> <div class=&qu ...

Issues with the functionality of Angular 2 routerLink

Unable to navigate from the homepage to the login page by clicking on <a routerLink="/login">Login</a>. Despite reviewing tutorials and developer guides on Angular 2 website. Current code snippet: index.html: <html> <head> ...

The symbol '★' represents the '★' content in CSS

Here is the CSS code I am using: .rating:not(:checked) > label:before { content: '★'; } However, when it is displayed on the screen, instead of seeing a ★, I see â˜. It's strange because if I use Firebug and manually change the ...

Chrome fails to load webfont upon page initialization

Encountering a problem with loading a WebFont specifically on Chrome version "48.0.2564.82 m (64-bit)". The issue arises from the webfont not being applied upon page load or navigation, unless I manually refresh the page. Below is the snippet of code fro ...

Instructions for authenticating with Google silently in the background

I implemented a Google authentication system based on the tutorial provided in this blog post. Link to Tutorial However, I am facing an issue where a popup always appears for users to login. I would prefer the login process to occur in the background, wh ...

Variety of formatting options for menu items when the menu is in its collapsed state

I am working with a Bootstrap nav-bar that collapses into a button by default. Within my nav-bar, I have opted for images instead of text links. However, when the nav-bar is collapsed, I would like these images to be smaller in size. Is there a way to cu ...

I am curious if there is a wysiwyg web editor extension specifically designed for VS2010 available?

In my experience, I have been working with C#, HTML coding using VS2010 and MVC. Utilizing VS2010 has proven to be an invaluable tool for me in this process. Currently, I find myself needing to create some straightforward static web pages. I am wondering ...

Creating a Full Height Background Image with a Responsive Width Using Jquery

I am facing an issue with my background image dimensions of 1400 in height and 1000 in width. When using any full-screen background jQuery plugin or code, the image crops from either the top or bottom to fit the entire screen. However, I am looking for a s ...

Generate an HTML table dynamically from a PostgreSQL query

I am facing a challenge that may be simple for experienced individuals but is proving to be difficult for me as a newbie. The task at hand involves retrieving JSON data from a database query and displaying it in an HTML table using Node.js, Express, and Po ...

Having trouble accessing static files with express? If you see the message "Cannot Get /", this might be the

After trying to learn how to read static files with Express from a reliable website, I encountered an issue. My terminal indicated that the operation was successful, but when I checked the website, it displayed "Cannot Get /" (as shown in the image). Despi ...

JQuery isn't functioning properly on dynamically generated divs from JavaScript

I'm currently tackling an assignment as part of my learning journey with The Odin Project. You can check it out here: Despite creating the divs using JavaScript or jQuery as specified in the project requirements, I am unable to get jQuery's .hov ...

Executing a parent window function from a child window using AngularJS

I'm working on a multi-page/window application where a dashboard page controls a list of children (windows). The dashboard should be able to call functions in the children and vice versa. However, I'm facing an issue where the child fails to invo ...

What is the best way to use jQuery to retrieve information from one child element in an XML API in order to locate another child

Hi there, I'm new to jQuery and could use some help. I'm attempting to retrieve specific information like CPU and RAM details from a particular phone model. I've written the jQuery code, but I'm having trouble displaying the RAM and CPU ...

Form with placeholders

Is there a way to personalize an email using different variables, like adding special characters such as $, {}, [] around the word to indicate it's a variable? For example, {name}. I'm looking for a plugin compatible with Angular 14+ that can ass ...

Manipulate CSS using jQuery's ID selector

I am attempting to modify a particular style of a div by its unique id, but it appears that my code is not functioning properly. The relevant codes are provided below: Jquery: $(document).ready(function () { $(".a_10.08.201223:56:49").hover(function(){ ...

Exploring Angular 2+: Asynchronous Testing with setTimeout

I have a question regarding my testing process. I am using Angular 6, karma, and jasmine. Here is the test I have written: it(`my test`, async(() => { console.log('### start test'); fixture.detectChanges(); // calling a method wi ...