1

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?

2
  • Please try to improve your question. What exactly is the problem? What is the expected behavior or outcome? Commented Mar 27, 2017 at 15:57
  • umm...I just want to know what is ngOutletContext and ngTemplateOutlet. Commented Mar 27, 2017 at 16:04

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

precisely explain!!thanks a lot . is any possible to use @contentChild when I use <template>?
Sure, you can use that as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.