Set Values on Generated Angular 2 Templates with Template Context

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 6 years ago
Updated 4 years ago

Angular 2 templates have a special let syntax that allows you to define and pass a context when they’re being generated.

[00:00] Most templates don't have inputs, and there's no real way to push the data in from a line like this. What you do is you set these let statements, these let attributes. If I say let description, then that description can live in here. We'll say description, that'll render that out. Copy and paste that here as well, then you say this attribute will be equal to description.

[00:28] This one is going to come off what's called a context for this template. The context is the second parameter, so if I say description is sweet, hit save. Now every time I click create template, you'll see sweet come through because sweet's being passed in the context. You can read the context values off of here, pass them into the let declarations, and then those are rendered out. So keep on clicking, sweet, sweet, sweet. It's sweet templates all the way down.

sa
sa
~ 6 years ago

Looks like the video is missing something in the start

Mike
Mike
~ 5 years ago

Love this series.