首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏全栈修仙之路

    Angular ng-template vs ng-container

    答案是有的,我们可以使用 ng-container 指令。 ng-container <ng-container> 是一个逻辑容器,可用于对节点进行分组,它将被渲染为 HTML中的 comment 元素。 来解决这个问题:

    <ng-container *ngSwitchCase="0">Text one</ng-container> <ng-container > ng-template vs ng-container 介绍完 ng-container 指令,我们来分析一下它跟 ng-template 指令有什么区别?

    </ng-template> <ng-container>

    In ng-container, no attributes.

    2.6K20发布于 2019-11-05
  • 来自专栏全栈修仙之路

    ng-content 中隐藏的内容

    为了演示上述情况,我们将 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>

    ` }) class Wrapper { items = [0, 0, 0];

    3.8K30发布于 2019-11-06
  • 来自专栏finleyMa

    Angular 实现一个 Dialog 组件

    dialogRef.show()">Show</button> <app-my-dialog class="dialog-container" dialogTitle="这是标题" #dialogRef> <ng-container class="dialog-body">

    这是内容

    </ng-container> <ng-container class= "dialog-footer"> <button (click)="dialogRef.close()">关闭</button> </ng-container> </app-my-dialog > dialogRef 是这个组件的引用别名 <ng-container class="dialog-body"> 类似Vue中的插槽,之内的html会替换组件内部的<ng-content select

    1.8K20发布于 2019-07-01
  • 来自专栏前端新视界

    Angular Material 的设计之美

    </button> <mat-menu #menulevel1="matMenu"> <ng-container *ngFor="let childLvl1 of menuItem.children </ng-container> </mat-menu> </ng-container> </mat-menu> 另外,菜单组件还可以实现 popover 的效果,不过需要做一些特殊处理,如下 {{element.position}} </ng-container> <! {{element.name}} </ng-container> <! -- Weight Column --> <ng-container matColumnDef="weight"> <th mat-header-cell *matHeaderCellDef

    6.3K30发布于 2019-09-29
  • 来自专栏小鑫同学编程历险记

    【Angular教程】-内容投影\u002F@ContentChild\u002F@ViewChild

    投影子元素 使用ng-container来包裹子元素,减少不必要的dom层,类似vue中的template 容器组件这样写

    编号4 <ng-content select="question "></ng-content>
    业务组件这样写 <app-page-container> <ng-container ngProjectAs="question">

    内容投影酷吗

    </ng-container> </app-page-container> 4. 使用ng-container定义我们的投影区块 使用ngTemplateOutlet指令来渲染ng-template元素。 通过内置的动态指令*ngIf来控制是否渲染投影。 ]="content.templateRef"> </ng-container>

    在业务组件中我们使用ng-template来包裹我们的实际元素。

    1.2K30编辑于 2022-12-25
  • 来自专栏全栈修仙之路

    Angular DOM 抽象概述

    答案是有的,就是使用 <ng-container> 元素。 示例 <ng-container *ngIf="lessons">

    {{lesson | json}}
    </ng-container> ngTemplateOutlet *ngTemplateOutlet="tpl"></ng-container> <ng-template #tpl> I am span in template</ng-container> <ng-template #tpl let-name let-location="location"> <span

    4.8K30发布于 2019-11-05
  • 来自专栏全栈修仙之路

    Angular 6.x 指令快速入门

    简单语法 <ng-container *ngComponentOutlet="componentTypeExpression"></ng-container> 完整语法 <ng-container *ngComponentOutlet ="componentTypeExpression; injector: injectorExpression; content: contentNodesExpression;"> </ng-container AlertDangerComponent { } @Component({ selector: 'my-app', template: `

    Angular version 6

    <ng-container *ngComponentOutlet="alert"></ng-container> <button (click)="changeComponent()">Change component<

    4.7K40发布于 2019-11-05
  • 来自专栏call_me_R

    Angular 中自定义 Video 操作

    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

    2.3K30编辑于 2022-04-15
  • 来自专栏全栈修仙之路

    Angular 网络连接状态组件

    现在我们来看一下如何使用: <connection> <ng-container *fast> Fast connection - Render a video </ng-container > <ng-container *slow> Slow connection - Render a placeholder </ng-container> </connection>

    2.1K30发布于 2019-11-06
  • 来自专栏全栈修仙之路

    Angular 内容投影

    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 组件。

    3.3K20发布于 2019-11-05
  • 来自专栏狮乐园

    高级 Angular 组件模式 (6)

    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对象包含的键值对会作为组件状态注入

    1.6K20发布于 2020-01-21
  • 来自专栏狮乐园

    高级 Angular 组件模式 (6)

    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对象包含的键值对会作为组件状态注入

    1.2K10发布于 2018-10-19
  • 来自专栏农历七月廿一

    angular知识点梳理第二篇-基本语法

    文章目录 前文回顾 基本语法 常见指令 NgModel NgFor NgIf Ng-container 管道 前文回顾 前面已经写了关于angular项目的基本介绍和如何创建一个angular项目,这一篇主要梳理一些 > 当前的isShow:{{isShow}}

    我是一个div块
    运行效果 true显示: false不显示: Ng-container ng-container 这里有必要介绍一下,这个类比的话就喝vue的template是基本一致的,不是完全一致,我们可以将它看作一个承载体,也就是说我们无法进行包裹判断的一些元素或者段落可以使用这个进行包裹

    3.7K30编辑于 2022-05-09
  • 来自专栏Google Dart

    AngularDart 4.0 高级-结构指令 顶

    -- 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>)

    <select [(ngModel)]="hero"> <ng-container *ngFor="let h of heroes "> <ng-container *ngIf="showSad || h.emotion ! == 'sad'"> <option [ngValue]="h">{{h.name}} ({{h.emotion}})</option> </ng-container> </ng-container

    18.6K20发布于 2018-08-14
  • 来自专栏call_me_R

    自定义 angular-datetime-picker 格式

    我们来讨论两点: 在输入框中显示 YYYY/MM/ HH:mm:ss 格式 翻译 - 更改按钮的名称 Cancel => 取消,Set => 设置 目前默认的值是这样的: 我们有相关的 html 代码如下: <ng-container selectedMoment" [owlDateTime]="dt"> <owl-date-time #dt [showSecondsTimer]="true"></owl-date-time> </ng-container

    1.6K20编辑于 2022-09-26
  • 来自专栏全栈修仙之路

    Angular 动态创建组件

    <ng-container *ngComponentOutlet="alertComponent"></ng-container> ` }) 更新 AppComponent 组件类,新增 alertComponent

    5K10发布于 2019-11-05
  • 来自专栏Nexent

    VibeCoding实践,AI能为开发提升多少效率?

    [ngModelOptions]="{standalone: true}" /> 仅显示zip/gz文件

    </form>
    <ng-container ngModelOptions]="{standalone: true}" />
    {{v.name}}
    </ng-container

    50710编辑于 2025-08-03
  • 来自专栏才浅coding攻略

    怎样在你的网页中嵌入展示3D奎爷模型(可360度观看)

    window.addEventListener("resize", () => { engine.resize(); }); 好的,ts中的逻辑代码就大功告成了,接下来要添加到HTML中展示模型和进度条: <ng-container renderCanvas" style="width: 98%;height: 83%;text-align: center;"></canvas> </ng-container

    1.2K50编辑于 2023-09-18
  • 来自专栏前端布道

    Angular开发实践(八): 使用ng-content进行组件内容投射

    'Hide' : 'Show' }} </button>

    <ng-container [ngTemplateOutlet]="template"></ng-container>
    ` }) export class DemoComponent implements

    3.5K81发布于 2018-04-11
  • 来自专栏前端开发

    Angular SSR 下的 HTTP 请求如何执行的?

    string;title:string;price:number};@Component({selector:'app-product-page',standalone:true,template:`<ng-container *ngIf="product$|asyncasp">

    {{p.title}}

    Price:{{p.price}}

    </ng-container>`,})exportclassProductPageComponent

    8210编辑于 2026-04-13
  • 第 2 页
    领券