Created
March 3, 2016 20:01
-
-
Save alincc/9c05a2710c5f7d5c2ea6 to your computer and use it in GitHub Desktop.
angular2 - append child to body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, Input, Output, EventEmitter, ElementRef, ViewChild, DynamicComponentLoader} from 'angular2/core'; | |
import {BrowserDomAdapter} from 'angular2/platform/browser'; | |
@Component({ | |
selector: 'parent', | |
providers: [BrowserDomAdapter] | |
}) | |
export class ParentComponent { | |
@ViewChild(Child) child: Child; | |
constructor( | |
el: ElementRef, | |
dcl: DynamicComponentLoader, | |
browserDomAdapter: BrowserDomAdapter | |
) { | |
} | |
show() { | |
this.dcl.loadIntoLocation(Child, this.el, 'dynamicChild') | |
.then(containerRef => { | |
this.dialogElement = containerRef.location.nativeElement; | |
this.browserDomAdapter.appendChild(this.browserDomAdapter.query('body'), this.dialogElement); | |
}); | |
} | |
hide() { | |
this.browserDomAdapter.removeChild(this.browserDomAdapter.query('body'), this.dialogElement); | |
this.dialogElement = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@touqeershafi this doesn't even work for angular2 anymore, because it was written for a very early version of it.