博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Angular] Configurable Angular Components - Content Projection and Input Templates
阅读量:4677 次
发布时间:2019-06-09

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

We are going to have a modal component:

And we can pass default modal body by content projection:

So 'modal-body' will be shown by default. 

 

Now we want to modal body can be configurable. We can choose to pass in a new template thought @Input, if template was passed in then use template instead of 'modal-body':

To do that, we defined a 'ng-template' and mark it as 'newModalBody' templateRef. It contians ours new template. And we can pass the template thought @Input.

 

So in the au-modal, it defines:

import {Component, Input, OnInit, TemplateRef} from '@angular/core';@Component({  selector: 'au-modal',  templateUrl: './au-modal.component.html',  styleUrls: ['./au-modal.component.scss']})export class AuModalComponent implements OnInit {  @Input() body: TemplateRef
; constructor() { } ngOnInit() { }}

 

In the component html, we need to check whether we pass in the template or not, if new template is present then we use it, otherwise, we fallback to default content projection:

The reason here we use two ng-container is because, for one ng-container can only have one structure directive (*ngIf or *ngTeplateOutlet).

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

你可能感兴趣的文章
[Node.js] node-persist: localStorage on the server
查看>>
jquery.event 研究学习之bind篇
查看>>
LOJ #108. 多项式乘法
查看>>
libusb开发指南
查看>>
SAS基础 -- 逻辑库不存在问题解决
查看>>
Servlet监听器统计在线人数
查看>>
第2章 数字之魅——寻找发帖“水王”
查看>>
eclipse jsp html 格式化 format
查看>>
关于手机端IOS系统微信中虚拟键盘遮挡input输入框问题的解决方案 草稿
查看>>
css3背景、边框、和补丁相关属性 (二)
查看>>
Python--小功能应用
查看>>
别做操之过急的”无效将军”,做实实在在的”日拱一卒”
查看>>
js去除范围内所有标签并显示指定字符串
查看>>
结对项目进度2
查看>>
git + git flow 的简单介绍
查看>>
Servlet详解(四)--Request与Response
查看>>
如果我们想要交换两个数字,就可以使用位运算
查看>>
求给出第 K个 N位二进制数,该二进制数不得有相邻的“1”
查看>>
P1059 明明的随机数【去重排序】
查看>>
HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
查看>>