question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I tried this loader yesterday, and I can’t figure out how to load icons, I’m working on an angular 2 app so I created a component that does more or less the same job as the react-one in the examples (see code below) but it does not display any icon.

from the README.md:

By default sprite renders when DOMContentLoaded event fires and injects as first child in document.body

  • I don’t see neither anything added to the body after page load (even before angular’s bootstrap) nor a single reference to a sprite.js script in the list of sources in Chrome.
  • I don’t have any output at compile or run time, it just does not render…
  • I removed my <base> tag

Here is my code :

import { Component, Input, OnInit, ElementRef} from '@angular/core';
var Glyphs = {};
var req = require.context("./icons", false, /\.svg$/);
req.keys().forEach(function(file: string) {
  var id = req(file);
  var name = /^\.\/(.*)\.svg$/.exec(file)[1];
  if (name) {
    Glyphs[name] = id;
  }
});

@Component({
  selector: 'lnk-icon',
  template: "",
  directives: [],
  providers: [],
  pipes: []
})
export class IconComponent implements OnInit {

  @Input("glyph")
  private glyph: string;

  constructor(private element: ElementRef) {
  }

  ngOnInit() {
    var svgns = "http://www.w3.org/2000/svg";
    var xlinkns = "http://www.w3.org/1999/xlink";
    var svg = document.createElementNS(svgns, "svg");
    var use = document.createElementNS(svgns, "use");
    use.setAttributeNS(xlinkns,"href",Glyphs[this.glyph]);
    svg.appendChild(use);
    this.element.nativeElement.appendChild(svg);
  }

}

and my webpack config:

//stuff
  module: {
     loaders:[{
      test: /\.svg$/,
      loader: "svg-sprite"
    }]
  },
//more stuff

Note that I first tried using Angular’s template syntax but didn’t work neither…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
kisenkacommented, Jul 7, 2016

@n00dl3 just remove svg from this line https://github.com/n00dl3/test_svg_sprite/blob/master/config/webpack.common.js#L28 😃 You override sprite-loader setup with file-loader.

1reaction
cartogramcommented, Oct 19, 2016

@n00dl3 Don’t feel so bad, I just did the exact same thing! Lucky for me I found this thread

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not rendering all icons in Windows 10 - Microsoft Community
Not rendering all icons in Windows 10. I have this problem. Cortana and Store do not show everything in it's app. Please see...
Read more >
Jdenticon doesn't render my icons
Icons are rendered for some placeholders, but not for others. No icons are rendered after navigating, but after a page refresh they are...
Read more >
Icons are not rendered anymore · Issue #11885 - GitHub
I noticed that (custom) icons are not rendered anymore after updating to the latest version of fabric. I then started rolling back the ......
Read more >
Icon previews not rendering - Apple Community
Icon previews not rendering. Ever since I updated to macOS Mojave, I noticed that icons within macOS are not rendering their previews.
Read more >
Why isn't my icon button rendered but not visible?
Something is occupying space on the app screen, but it is not visible. There is no error on the IDE, and it takes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found