大佬教程收集整理的这篇文章主要介绍了angular – elementRef.nativeElement.remove()对浏览器有任何负面影响吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果元素被销毁并且超时执行以删除已经被破坏的组件,那么是否存在任何不可见的负面影响?
export class AnimationCloserComponent { public queryParams$; constructor( private router: Router,private elementRef:ElementRef,private activatedRoute:ActivatedRoutE) {} ngOnInit() { /* Will look for routIng instructions with QueryParams to route and close this component. these instructions may sometimes not be available.. */ this.queryParams$= this.activatedRoute .queryParAMMap .map(params => { let cloSEOutletName = params.get('cloSEOutlet') || null; if (cloSEOutletName != null) { this.router.navigate(['',{ outlets: { [cloSEOutletName]: null }}]); } return params.get('cloSEOutlet') || null; } ); /* This is meant to destroy the component if the router Could not route away from it. */ setTimeout(()=>{ this.elementRef.nativeElement.remove(); },1500); } }
我真的想问一下,在我做这个练习之前,这样做是否合适. (已在下面澄清)
ComponentA ComponentB
视图层次结构将是这样的:
ComponentAView ElementNode('<b-comp>',document.createElement('<b-comp>')) ComponentBView ... ComponentClassnode(new ComponentB());
如果删除第一个元素< b-comp>来自DOM Angular一无所知.它将继续认为有一个子组件可用.
这可能会导致意外后果,例如Angular报告@ViewChildren中的子组件,同时将其从DOM中删除.
以上是大佬教程为你收集整理的angular – elementRef.nativeElement.remove()对浏览器有任何负面影响吗?全部内容,希望文章能够帮你解决angular – elementRef.nativeElement.remove()对浏览器有任何负面影响吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。