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.