Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 2如何加载SVG图像?_Svg_Angular - Fatal编程技术网

Angular 2如何加载SVG图像?

Angular 2如何加载SVG图像?,svg,angular,Svg,Angular,我在Angular 2模板中尝试了以下代码: <ul class="products"> <li *ngFor="#p of products"> <svg width="200" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/19

我在Angular 2模板中尝试了以下代码:

<ul class="products">
  <li *ngFor="#p of products">
    <svg width="200" height="100" xmlns="http://www.w3.org/2000/svg"
         xmlns:svg="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink">
         <g>
            <title>{{p.Name}}</title>
            <image xlink:href="http://somewhere.com/{{p.Picture1}}"
                   id="svg_21" height="176.731579" width="117" y="28" x="32" />
        </g>
    </svg></li></ul>

但是在使用该选项的过程中,我得到了一个错误:找不到
我的应用程序

在发布问题几秒钟后,我找到了答案:

<image *ngIf="p.Picture1" attr.xlink:href="http://somewhere.com/{{p.Picture1}}" />

显然,如果
p.Picture1
为空,则更有可能使html或SVG无效,从而导致找不到
my app
,如下所示

attr.xlink:href="http://somewhere.com/{{p.Picture1}}"
<image *ngIf="p.Picture1" attr.xlink:href="http://somewhere.com/{{p.Picture1}}" />