答案是有的,我们可以使用 ng-container 指令。 ng-container <ng-container> 是一个逻辑容器,可用于对节点进行分组,它将被渲染为 HTML中的 comment 元素。 来解决这个问题:
In ng-container, no attributes.
为了演示上述情况,我们将 Counter 组件包装在一个 <ng-container> 中,看看我们的目标投影会发生什么: <wrapper> <ng-container> <counter ></counter> </ng-container> </wrapper> 现在我们的 couter 组件会被投影到第一个红色框中。 因为 ng-container 容器不再匹配 select="counter"。为了解决这个问题,我们必须使用 ngProjectAs 属性,它可以应用于任何元素上。 具体如下: <wrapper> <ng-container ngProjectAs="counter"> <counter></counter> </ng-container> </wrapper [ngTemplateOutlet]="template"></ng-container>
dialogRef.show()">Show</button> <app-my-dialog class="dialog-container" dialogTitle="这是标题" #dialogRef> <ng-container class="dialog-body">
这是内容
</button> <mat-menu #menulevel1="matMenu"> <ng-container *ngFor="let childLvl1 of menuItem.children </ng-container> </mat-menu> </ng-container> </mat-menu> 另外,菜单组件还可以实现 popover 的效果,不过需要做一些特殊处理,如下
投影子元素 使用ng-container来包裹子元素,减少不必要的dom层,类似vue中的template 容器组件这样写
内容投影酷吗
</ng-container> </app-page-container> 4. 使用ng-container定义我们的投影区块 使用ngTemplateOutlet指令来渲染ng-template元素。 通过内置的动态指令*ngIf来控制是否渲染投影。 ]="content.templateRef"> </ng-container>答案是有的,就是使用 <ng-container> 元素。 示例 <ng-container *ngIf="lessons">
简单语法 <ng-container *ngComponentOutlet="componentTypeExpression"></ng-container> 完整语法 <ng-container *ngComponentOutlet ="componentTypeExpression; injector: injectorExpression; content: contentNodesExpression;"> </ng-container AlertDangerComponent { } @Component({ selector: 'my-app', template: `
12px;">播放 ✅</button> <button nz-button nzType="primary" (click)="pause('btn')">暂停 ✅</button> <ng-container nz-menu-item (click)="forwardSecond(20)">快进 20 s </nz-dropdown-menu> </ng-container > <ng-container> <button nz-button nz-dropdown [nzDropdownMenu]="menuBack" nzPlacement="bottomCenter > <<em>ng-container</em>> <button nz-button nz-dropdown [nzDropdownMenu]="speedUp" nzPlacement="bottomCenter li nz-menu-item (click)="speedUpVideo(4)">4 倍 </nz-dropdown-menu> </ng-container
现在我们来看一下如何使用: <connection> <ng-container *fast> Fast connection - Render a video </ng-container > <ng-container *slow> Slow connection - Render a placeholder </ng-container> </connection>
ngProjectAs 有时候我们的定义的组件可能会包含在其它容器中,比如 <ng-container> ,这时我们的目标投影会发生什么: <ng-container> <auth-remember (checked)="rememberUser($event)"></auth-remember> </ng-container> 当你刷新页面的时候,你会发现 AuthRememberComponent 因为 ng-container 容器不再匹配 select="auth-remember"。为了解决这个问题,我们必须使用 ngProjectAs 属性,它可以应用于任何元素上。 使用方式如下: <ng-container ngProjectAs="auth-remember"> <auth-remember (checked)="rememberUser($event)" ></auth-remember> </ng-container> 通过设置 ngProjectAs 属性,终于重新找回了我们的 AuthRememberComponent 组件。
Toggle 组件 <toggle>组件能够通过ContentChild装饰器得到关于<ng-template>的引用,之后会赋予模板在渲染时所需要的状态,代码如下: <ng-container * ngTemplateOutlet="layoutTemplate; context: { on: this.on, toggle: this.toggle, fns: { toggle: this.toggle } }"> </ng-container > 这里<ng-container>被当做一个占位符来使用,之后你可以使用*ngTemplateOutlet指令来填充它,layoutTemplate变量指代的是需要被渲染的模板,context对象包含的键值对会作为组件状态注入
Toggle 组件 <toggle>组件能够通过ContentChild装饰器得到关于<ng-template>的引用,之后会赋予模板在渲染时所需要的状态,代码如下: <ng-container * ngTemplateOutlet="layoutTemplate; context: { on: this.on, toggle: this.toggle, fns: { toggle: this.toggle } }"> </ng-container > 这里<ng-container>被当做一个占位符来使用,之后你可以使用*ngTemplateOutlet指令来填充它,layoutTemplate变量指代的是需要被渲染的模板,context对象包含的键值对会作为组件状态注入
文章目录 前文回顾 基本语法 常见指令 NgModel NgFor NgIf Ng-container 管道 前文回顾 前面已经写了关于angular项目的基本介绍和如何创建一个angular项目,这一篇主要梳理一些 > 当前的isShow:{{isShow}}
-- No ng-container yet:
I turned the corner <ng-container *ngIf="hero ! I waved </ng-container> and continued on my way. showSad">show sad</label>)
我们来讨论两点: 在输入框中显示 YYYY/MM/ HH:mm:ss 格式 翻译 - 更改按钮的名称 Cancel => 取消,Set => 设置 目前默认的值是这样的: 我们有相关的 html 代码如下: <ng-container selectedMoment" [owlDateTime]="dt"> <owl-date-time #dt [showSecondsTimer]="true"></owl-date-time> </ng-container
<ng-container *ngComponentOutlet="alertComponent"></ng-container> ` }) 更新 AppComponent 组件类,新增 alertComponent
[ngModelOptions]="{standalone: true}" /> 仅显示zip/gz文件
window.addEventListener("resize", () => { engine.resize(); }); 好的,ts中的逻辑代码就大功告成了,接下来要添加到HTML中展示模型和进度条: <ng-container renderCanvas" style="width: 98%;height: 83%;text-align: center;"></canvas> </ng-container
'Hide' : 'Show' }} </button>
string;title:string;price:number};@Component({selector:'app-product-page',standalone:true,template:`<ng-container *ngIf="product$|asyncasp">
Price:{{p.price}}
</ng-container>`,})exportclassProductPageComponent