Reputation: 1402
I want to set dynamic template in my page, that I use but info is limited.
Set @Viewchild
and @ContentChild
to assign template
, that's a great example on web (i.e. light DOM and shadow DOM , REF).
ngOutletContext
and ngTemplateOutlet
,however, are limited too.You can search experiment
tag.Can someone please explain and somebody use <template let-item>
.Is that the same way?
Upvotes: 1
Views: 68
Reputation: 658245
update Angular 5
ngOutletContext
was renamed to ngTemplateOutletContext
See also https://github.com/angular/angular/blob/master/CHANGELOG.md#500-beta5-2017-08-29
original
You can create a template and then pass it around and ngTemplateOutlet
allows to render such a template. ngOutletContext
allows to pass data to the template.
let-item
allows to reference the value passed as $implicit
<template #foo let-item>
{{item}}
</template>
<template [ngTemplateOutlet]="foo" ngOutletContext="{$implicit: 'bar'}"></template>
or to use any other passed value
<template #foo let-item="bar">
{{item}}
</template>
<template [ngTemplateOutlet]="foo" ngOutletContext="{bar: 'baz'}"></template>
Instead of using a template variable and referencing the template within the same component, you can also use @ViewChild()
to get a reference of the template and pass it around to render the template in another component.
Upvotes: 1