最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - Using Renderer2 removeChild with parent set as null - Stack Overflow

programmeradmin0浏览0评论

I'm using Renderer2 to render some custom elements in an Angular application. As each element is created, it is stored as a constant:

const myNewElement = this.renderer2.createElement('div');

When the time comes to remove this element, I am using removeChild. This has a parameter for the parent of the node being removed:

removeChild(parent: any, oldChild: any, isHostElement?: boolean | undefined)

However if I set parent to null, it seems to remove oldChild from the DOM successfully and without throwing an error:

this.renderer2.removeChild(null, myNewElement); // Works!

Could this approach cause any potential issues? Should a parent element be specified, even if removeChild works without it?

发布评论

评论列表(0)

  1. 暂无评论