博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Angular Directive] Assign a Structual Directive a Dynamic Context in Angular 2
阅读量:5157 次
发布时间:2019-06-13

本文共 1270 字,大约阅读时间需要 4 分钟。

 Just like passing in an array to 
*ngFor, you can pass in any value into your structural directive so that it can render templates based on those values. It's crucial to understand how the 
*directive syntax expands into a 
<template> and adds a custom 
@Input based on the syntax you use so that you can use your own data.
 
 
The syntax looks like:

{
{message.to}} - {
{message.message}}

 

For template it would looks like:

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, two, 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
, private view: ViewContainerRef) { }}

 

 

 

转载于:https://www.cnblogs.com/Answer1215/p/6290872.html

你可能感兴趣的文章
(CSharp)克隆控件事件
查看>>
AsyncHttpClient 官网的东西
查看>>
整理:GET与POST的区别
查看>>
iOS开发UI篇—九宫格坐标计算
查看>>
晨间日记的奇迹
查看>>
19. Remove Nth Node From End of List
查看>>
python_day13 CSS
查看>>
课后作业2(构建之法阅读计划)
查看>>
跟踪域名节点
查看>>
python工具 fabfile.py 部署svn 上的代码
查看>>
随机森林算法
查看>>
final关键字介绍
查看>>
第二课 Ubuntu环境搭建和图形界面操作
查看>>
Internet Explorer 8之我见
查看>>
java基础总结
查看>>
CentOS7防火墙firewalld设置
查看>>
jsp面试题
查看>>
scrapy crawl itcast -o teachers.json 爬虫案列
查看>>
[leetcode]Backtracking-39. Combination Sum
查看>>
linux内核分析第四次实验
查看>>