Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[feature] A directive to insert / stamp out TemplateRefs #7615

Closed
@pkozlowski-opensource

Description

@pkozlowski-opensource

There are cases where we've got a reference to a TemplateRef and would like to use it to stamp out live HTML fragments. Currently it can be easily done from the JS side (viewContainerRef.createEmbeddedView(tplRef)) but this issue is about creating a directive that would allow us to do this "inserting" from a template.

A "workish" example of such directive:

@Directive({
    selector: 'ng-insert-tpl'
})
export class NgInsertTpl {
    constructor(private _viewContainerRef: ViewContainerRef) {
    }

    @Input() set template(tplRef: TemplateRef) {
        this._viewContainerRef.createEmbeddedView(tplRef);
    }
}

Naming things is hard so ng-insert-tpl is definitively up to debate.

This is part of #7546 (comment), it could be used in action like so: http://plnkr.co/edit/sleVVrgqo66JN9G48yyj?p=preview

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonIssues related to APIs in the @angular/common packagefeatureIssue that requests a new featurestate: Needs Design

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions