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

I'm using Renderer2 to render some custom elements in an Angular application. As each element is c

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744758250a4592011.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信