[Angular Directive] Assign a structual Directive a Dynamic Context in Angular 2

Source: Internet
Author: User
Tags export class

 Just like passing in a array to *ngFor, you can pass in any value into the your structural directive so the it can render templates based on those values. It ' s crucial to understand how the *directiveSyntax expands into a <template>and adds a custom @InputBased on the syntax, you can use your own data. The syntax looks like:
<*three= "Let message from Messages">{{message.to}}-{{ Message.message}}</h2>

For template It would looks like:

<[Threefrom]= "Messages"></template> 

It Combimes ' three ' and ' from ' keywords.

So the directive would looks like:

Import {Directive, Input, Templateref, viewcontainerref} from "@angular/core"; @Directive ({selector:' [Three] '}) Export class Threedirective {@Input () set Threefrom({One, one, one, three}) { This. View.createembeddedview ( This. Template, {$implicit: {to:"People" +math.random (), Message:two}});  This. View.createembeddedview ( This. Template, {$implicit: {to:"People" +math.random (), Message:three}});  This. View.createembeddedview ( This. Template, {$implicit: {to:"People" +math.random (), Message:one}}); } constructor (Private Template:templateref<any>, Private View:viewcontainerref) {  }}

[Angular Directive] Assign a structual Directive a Dynamic Context in Angular 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.