简体   繁体   English

Angular2 innerHtml不断更新

[英]Angular2 innerHtml constantly updating

I think this is more of a style question than anything but I want to make sure I am doing this correctly. 我认为这比什么都更是一个风格问题,但我想确保自己正确地做到了。

I have an endpoint that I am calling which is annoyingly returning a SVG image instead of a full jpeg or png and I need to display that on the page. 我有一个正在呼叫的端点,该端点烦人地返回了SVG图像,而不是完整的jpeg或png,因此需要在页面上显示该端点。 I created a service that calls out and grabs the SVG. 我创建了一个服务,该服务可以调出并获取SVG。 That service gets called from a method in the component called getImage(id). 该服务从组件中的方法getImage(id)调用。

In my HTML I have something like: 在我的HTML中,我有类似以下内容:

<div [innerHtml]="getImage(id)></div>

One thing I noticed is that I can't really inspect the SVG in chrome because it's constantly updating. 我注意到的一件事是,我无法真正检查Chrome中的SVG,因为它会不断更新。 I am wondering if this is a problem and if so how to fix it? 我想知道这是否有问题,如何解决? It looks like it's just constantly calling the update method but nothing has changed on the page (as far as I can tell) so the change detection shouldn't be triggered? 看起来它只是不断地调用update方法,但是页面上没有任何更改(据我所知),因此不应触发更改检测?

Example for my comment: 我的评论示例:

import { ..., OnInit, ... } from '@angular/core'

@Component({ ... })
export class ...Component implements OnInit {
   private image: string;

   constructor(...) { ... }

   public ngOnInit(): void {
      this.getImage(1); //Get id from somewhere
   }

   private getImage(id): void {
      ...
      this.image = ...;
   }
}

HTML 的HTML

<div [innerHtml]="image"></div>

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

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