简体   繁体   English

有没有办法为 svg 元素内的图像元素动态设置 y 属性?

[英]Is there a way to dynamically set y attribute for an image element inside svg element?

As stated in the question, I wonder if there is a way to set y attribute for an image element inside svg, because everytime user provides different image, I need to change image's “y” attribute value.如问题所述,我想知道是否有办法为 svg 内部的图像元素设置 y 属性,因为每次用户提供不同的图像时,我都需要更改图像的“y”属性值。 Right now when I try to use binding in Angular, I get the following error:现在,当我尝试在 Angular 中使用绑定时,出现以下错误:

在此处输入图像描述

My code for embedding image inside svg looks like this:我在 svg 中嵌入图像的代码如下所示:

            <svg class="conversation-image-preview">
              <image *ngIf="inConversationIconInfo.previewUrl" 
              [attr.href]="inConversationIconInfo.previewUrl" 
              [y]="inConvImageY" 
                 />
            </svg>

I'd really appreciate any help.我真的很感激任何帮助。

The JavaScript strict mode-only exception "setting getter-only property" occurs when there is an attempt to set a new value to a property for which only a getter is specified. JavaScript 严格模式例外“设置 getter-only 属性”在尝试为仅指定 getter 的属性设置新值时发生。

In your case SVGImageElement is only having getter element, and when you trying to attempt set value it throwing error in console.在您的情况下 SVGImageElement 仅具有 getter 元素,并且当您尝试设置值时,它会在控制台中引发错误。

You can see in document of SVGImageElement where y attribute is read only .您可以在SVGImageElement 的文档中看到 y 属性是read only的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM