[Angular] Remove divs to Preserve Style and Layout with ng-container in Angular
The Angular <ng-container>
is a grouping element that doesn't interfere with styles or layout because Angular doesn't put it in the DOM.
When we using Content Projection in a DUMP component:
<div class="card" style="width: 18rem;">
<ng-content select=".heading"> </ng-content>
<div class="card-body">
<ng-content select=".body"> </ng-content>
</div>
</div>
We are using <ng-content> here to get projected element from the SMAR component:
<app-card>
<div class="heading"> <!-- add a extra div with class selector to wrap the elements -->
<img class="card-img-top" src="https://picsum.photos/g/200/300" alt="Card image cap">
</div>
<div class="body"> <!-- add a extra div with class selector to wrap the elements -->
<h5 class="card-title">Card Title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</app-card>
It ends up we have a extra div in the DOM, to remove that extra div, we just need to replace 'div' with 'ng.container':
<app-card>
<ng-container class="heading">
<img class="card-img-top" src="https://picsum.photos/g/200/300" alt="Card image cap">
</ng-container>
<ng-container class="body">
<h5 class="card-title">Card Title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</ng-container>
</app-card>
[Angular] Remove divs to Preserve Style and Layout with ng-container in Angular的更多相关文章
- angular学习的一些小笔记(中)之基础ng指令
一.布尔属性指令: ng-disabled:就是ng-disabled=true-->就指向不可用 <!doctype html> <html ng-app="&qu ...
- Visual Studio Code作为Angular开发工具常用插件安装、json-server安装与使用、angular/cli安装失败问题
前提准备: 搭建好Angular开发环境 1 安装Visual Studio Code 教程简单,不会的去问度娘 2 安装Chrome浏览器 教程简单,不会的趣闻度娘 3 Visual Studio ...
- [Angular] Improve Server Communication in Ngrx Effects with NX Data Persistence in Angular
Communicating with a remote server via HTTP presents an extra level of complexity as there is an inc ...
- Angular14 Visual Studio Code作为Angular开发工具常用插件安装、json-server安装与使用、angular/cli安装失败问题、emmet安装
前提准备: 搭建好Angular开发环境 1 安装Visual Studio Code 教程简单,不会的去问度娘 2 安装Chrome浏览器 教程简单,不会的趣闻度娘 3 Visual Studio ...
- AngularJS进阶(三十九)基于项目实战解析ng启动加载过程
基于项目实战解析ng启动加载过程 前言 在AngularJS项目开发过程中,自己将遇到的问题进行了整理.回过头来总结一下angular的启动过程. 下面以实际项目为例进行简要讲解. 1.载入ng库 2 ...
- [转]VS Code 扩展 Angular 6 Snippets - TypeScript, Html, Angular Material, ngRx, RxJS & Flex Layout
本文转自:https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode VSCode Angular Typ ...
- 使用 angular directive 和 json 数据 D3 随着标签 donut chart演示样本
使用angular resource载入中priorityData.json中间json数据,结合D3绘制甜甜圈图.执行index.html其结果见于图.: priorityData.json中jso ...
- Angular 2 to Angular 4 with Angular Material UI Components
Download Source - 955.2 KB Content Part 1: Angular2 Setup in Visual Studio 2017, Basic CRUD applicat ...
- angularJs , json,html片段,bootstrap timepicker angular
css .demotest { width: %; height: auto; overflow: auto; position: relative; margin: auto; margin-top ...
随机推荐
- servlet.txt笔记
javase jdbc ==>java访问数据库html ==>浏览器显示内容,无法把数据提交给后台?==>动态网页技术(servlet)解决前台.后台交互问题动态网页技术:serv ...
- 334 Increasing Triplet Subsequence 递增的三元子序列
给定一个未排序的数组,请判断这个数组中是否存在长度为3的递增的子序列.正式的数学表达如下: 如果存在这样的 i, j, k, 且满足 0 ≤ i < j < k ≤ n-1, ...
- 鼠标单击到 img行的时候图片隐藏方案
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 使用XUL开发跨平台桌面应用
先上图: 现在使用html,css,js开发桌面的优势越来越明显了,硬件性能的不断提升,人力成本越发昂贵,用户对界面要求越来越高,全球化下企业间的竞争越发激烈. 桌面软件50%+的工作量都在界面开发这 ...
- Ubuntu16安装jdk8配置Tomcat9
一.配置jdk 1.下载解压是肯定不能少的 2.配置环境变量根据自己需求来 export JAVA_HOME=/usr/software/jdk1.8.0_121 export CLASSPATH=. ...
- js indexOf 列表筛选
先来一堆效果图: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- JS——undefined、null
1.undefined == false //返回false 2.null == false //返回false 3.undefined == null //返回true 4.und ...
- jQuery——this
js注册事件this代表的dom对象 jQuery注册事件this代表的也是dom对象,所以需要$(this)转成jQuery对象
- hibernate注解之@Onetomany、@Manytoone、@JoinColumn
@Onetomany用于实体类与数据库表映射中少的一方,请看下面的例子. 假设一个用户只有一种角色,用户和角色是onetomany的关系 用户实体 @Entity @Table(name=" ...
- todey
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> 框架集fromset ...