Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active December 7, 2018 03:44
Show Gist options
  • Select an option

  • Save NetanelBasal/d911e9b69c5f1738946880cb10aa5c9b to your computer and use it in GitHub Desktop.

Select an option

Save NetanelBasal/d911e9b69c5f1738946880cb10aa5c9b to your computer and use it in GitHub Desktop.
@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;
}
}
@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