Last active
December 7, 2018 03:44
-
-
Save NetanelBasal/d911e9b69c5f1738946880cb10aa5c9b to your computer and use it in GitHub Desktop.
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
| @Component({ | |
| selector: 'hello', | |
| template: `<h1>Hello {{name}}!</h1>` | |
| }) | |
| export class HelloComponent { | |
| _name; | |
| @Input() set name(name: string) { | |
| this._name = name; | |
| } | |
| get name() { | |
| return this._name; | |
| } | |
| } |
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
| @Component({ | |
| selector: 'app-parent', | |
| template: `<p>Parent:</p><ng-container #vcr></ng-container>` | |
| }) | |
| export class ParentComponent implements OnInit { | |
| @ViewChild('vcr', { read: ViewContainerRef }) vcr: ViewContainerRef; | |
| constructor(private fr: ComponentFactoryResolver) { | |
| } | |
| ngOnInit() { | |
| const factory = this.fr.resolveComponentFactory(HelloComponent); | |
| const ref = this.vcr.createComponent(factory); | |
| ref.instance.name = 'World'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment