angular - Does elementRef.nativeElement.remove() have any negative effects on the browser? -


i'm setting timeout destroy component on angular 2 may destroyed before timeout called. timeout called either way , .remove() on native element of component (even though no longer in dom).

if element destroyed , timeout executes remove destroyed component there negative side affects not visible?

export class animationclosercomponent {     public queryparams$;      constructor(         private router: router,         private elementref:elementref,         private activatedroute:activatedroute) {}          ngoninit() {         /* routing instructions queryparams route , close component. these instructions may not 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;                 }             );          /* meant destroy component if router not route away it. */         settimeout(()=>{             this.elementref.nativeelement.remove();         }, 1500);     }     } 

i wanted ask if doing ok before make practice. (already clarified below)

it never ok remove native dom elements without angular knowing it. angular keeps component related nodes (including child components) in abstraction called view. nodes in view point dom elements. consider following setup:

componenta    componentb 

the view hierarchy this:

componentaview     elementnode('<b-comp>', document.createelement('<b-comp>'))         componentbview            ...     componentclassnode(new componentb()); 

if remove first element <b-comp> dom angular knows nothing it. continue thinking there's child component available.

this may result in unexpected consequences angular reporting child component in @viewchildren while have removed dom.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -