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

    Angular ng-template vs ng-container

    要解决该问题,我们可以使用 <ng-template> 的标准语法 (非*ngIf 语法糖): <ng-template [ngIf]="show">

    Div one</h2 vs ng-container 介绍完 ng-container 指令,我们来分析一下它跟 ng-template 指令有什么区别? 我们先看以下示例: <ng-template>

    In template, no attributes. 即 <ng-template> 中的内容不会显示。 最后我们来总结一下 <ng-template> 和 <ng-container> 的区别: <ng-template> :使用 * 语法糖的结构指令,最终都会转换为 <ng-template> 或 <template

    2.6K20发布于 2019-11-05
  • 来自专栏前端侠2.0

    ng6的ng-template的一个用法 原

    组件模板: <ng-template #tpl>      

    i am in tpl {{name }}
    </ng-template> ts 组件内: @ViewChild

    1.8K30发布于 2018-09-21
  • 来自专栏finleyMa

    Angular ngIf 跟他的新伙伴 else 和 then

    注意,else 绑定指向的是一个带有 #elseBlock 标签的 <ng-template> 元素。 该模板可以定义在此组件视图中的任何地方,但为了提高可读性,通常会放在 ngIf 的紧下方。 text while primary text is hidden</ng-template> then

    this is ignored
    <ng-template #primaryBlock>Primary text to show</ng-template> <ng-template #secondaryBlock >Secondary text to show</ng-template> <ng-template #elseBlock>Alternate text while primary text is hidden </ng-template> 总结: 你完全可以不用 else 和 then,这样会导致写一堆ngIf,代码可读性比较差。

    1.8K20发布于 2019-02-25
  • 来自专栏全栈修仙之路

    Angular 动态创建组件

    接下来模板元素 <ng-template> 将会作为我们的组件容器,具体示例如下: import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: ` <ng-template #alertContainer></ng-template> ` }) export class #alertContainer></ng-template> ` }) export class AppComponent { @ViewChild("alertContainer", { read #alertContainer></ng-template> <button (click)="createComponent('success')">Create success alert @Component({ selector: 'my-app', template: ` <ng-template #alertContainer></ng-template>

    4.9K10发布于 2019-11-05
  • 来自专栏小鑫同学编程历险记

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

    有条件的内容投影 中文网的描述: 如果你的组件需要_有条件地_渲染内容或多次渲染内容,则应配置该组件以接受一个 ng-template 元素,其中包含要有条件渲染的内容。 使用 ng-template 元素,你可以让组件根据你想要的任何条件显式渲染内容,并可以进行多次渲染。在显式渲染 ng-template 元素之前,Angular 不会初始化该元素的内容。 使用ng-container定义我们的投影区块 使用ngTemplateOutlet指令来渲染ng-template元素。 通过内置的动态指令*ngIf来控制是否渲染投影。 <app-page-container>

    <button appToggle>切换</button>
    <ng-template appContent > <app-my-hello>有条件的内容投影~</app-my-hello> </ng-template> </app-page-container> 现在你会发现页面并没有像前面那么顺利的正常渲染

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

    Angular 6.x 指令快速入门

    </ng-template> `, }) export class AppComponent implements AfterViewInit{ @ViewChild('tpl') tplRef </ng-template> <ng-template #atpl> Hello, Angular! #stpl let-message="message">

    {{message}}

    </ng-template> <ng-template #atpl let-msg ="message">

    {{msg}}

    </ng-template> <ng-template #otpl let-msg>

    {{msg}}< 微语法解析器把这个字符串转换成 <ng-template> 上的属性。

    4.6K40发布于 2019-11-05
  • 来自专栏狮乐园

    高级 Angular 组件模式 (6)

    06 Use <ng-template> 原文: Use <ng-template> Render Props最近在React社区中引起了轰动,但是与之类似的模式在Angular中似乎并没有得到太多关注 Note: TemplateRef是一个类名而<ng-template>是一个html标签,它们本质上是相同的。 不过你可能会在项目中更频繁地使用<ng-template>,但是在网上你可以很容易的搜索到关于TemplateRef的知识,因为<ng-template>会给你提供很多html5中的<template> 实现 <ng-template>组件可以完美地解决问题。 1. 父组件 从toggle组件中传入的状态是通过let关键字在父组件的<ng-template>标签上显示声明的。

    1.2K10发布于 2018-10-19
  • 来自专栏狮乐园

    高级 Angular 组件模式 (6)

    06 Use <ng-template> 原文: Use <ng-template> Render Props最近在React社区中引起了轰动,但是与之类似的模式在Angular中似乎并没有得到太多关注 Note: TemplateRef是一个类名而<ng-template>是一个html标签,它们本质上是相同的。 不过你可能会在项目中更频繁地使用<ng-template>,但是在网上你可以很容易的搜索到关于TemplateRef的知识,因为<ng-template>会给你提供很多html5中的<template> 实现 <ng-template>组件可以完美地解决问题。 1. 父组件 从toggle组件中传入的状态是通过let关键字在父组件的<ng-template>标签上显示声明的。

    1.6K20发布于 2020-01-21
  • 来自专栏全栈修仙之路

    Angular DOM 抽象概述

    示例 前面我们已经介绍了如何使用 HTML5 template 模板元素,下面我们来看一下如何使用 <ng-template> 元素。 @Component({ selector: "hello-world", template: `

    Hello World

    <ng-template #tpl> I am span in template </ng-template> ` }) export class HelloWorldComponent #tpl> I am span in template </ng-template> ` }) export class HelloWorldComponent #tpl let-name let-location="location"> I am {{name}} in {{location}} </ng-template

    4.7K30发布于 2019-11-05
  • 来自专栏finleyMa

    Angular 组件动态传入模板

    image.png 也可以通过 <nz-back-top [nzTemplate]="tpl" [nzVisibilityHeight]="100" (nzOnClick)="notify()"> <ng-template #tpl>

    UP
    </ng-template> </nz-back-top> 添加自定义模板。

    2.4K20发布于 2018-12-28
  • 来自专栏CRPER折腾记

    NG2&4折腾记 --- 记NG2升级NG4 RC1之修正问题跑起来

    ---- 问题1:template标签已经废弃了 信息来源:启动的时候控制台有提示,官方日志也有说 解决方案:全局搜索<template></template> ,替换<ng-template></ng-template ** ---- NG4的亮点 新的视图引擎,据说能让渲染更快 加强了*ngIf,里面可以写else了,这里直接拿官方的写法<ng-template #loading>Loading... </ng-template>

    {{ user.name }}
    复制代码

    62310发布于 2018-08-28
  • 来自专栏前端新视界

    基于 Angular Material 的 Data Grid 设计实现

    普通方法 <mtx-grid [data]="list" [columns]="columns"> </mtx-grid> <ng-template #statusTpl let-row </mat-slide-toggle> </ng-template> export class AppComponent implements OnInit { @ViewChild('statusTpl data]="list" [columns]="columns" [cellTemplate]="{ city: cityTpl }"> </mtx-grid> <ng-template "columns" [expandable]="true" [expansionTemplate]="expansionTpl"> </mtx-grid> <ng-template #expansionTpl let-row> {{row.name}} </ng-template> 在列定义中设置 showExpand, 确定在哪个列显示展开符号。

    6.3K20发布于 2020-06-29
  • 来自专栏call_me_R

    Angular 中结构指令模式 - 它们是什么且怎么使用

    {{worker.name}}
    Angular 生成一个 <ng-template> 的元素,然后应用 *ngIf 指令。
    的其余部分,包含类名,插入到 <ng-template> 里。 比如: <ng-template [ngIf]="worker">
    {{worker.name}}
    </ng-template> Angular 结构指令是怎么工作的

    5.2K20编辑于 2022-09-26
  • 来自专栏Angular学习规划

    Angular核心概念:数据绑定

    <any *ngIf=“布尔表达式”;else ELSE块的编号> <ng-template # ELSE块的编号> … 举例: html文件 <div *ngIf="isPayingUser </div> <<em>ng-template</em> #forChildren>此处是未成年的宝宝看的...</<em>ng-template</em>> <! -- ngIf,else此处只能用NG模板元素<em>ng-template</em>,该容器可以存放其他标签 --> ts文件: isPayingUser = true;//该用户是否为付费用户 //isPayingUser

    5.2K10编辑于 2022-06-28
  • 来自专栏风吹杨柳

    angularJS学习之路(三十)---自定义指令---templateUrl

    meta charset="utf-8"> <title></title> </head> <body>

    <script type="text/<em>ng-template</em> -- <script type="text/ng-template" id="zippy.html">
    <h3 ng-click="toggleContent -- <script type="text/ng-template" id="zippy.html">
    <h3 ng-click="toggleContent

    71520发布于 2019-07-08
  • 来自专栏全栈修仙之路

    Angular 网络连接状态组件

    组件和相关的 Connection 指令: connection.component.ts @Component({ selector: 'connection', template: ` <ng-template [ngTemplateOutlet]="fast.tpl" *ngIf="isFast"></ng-template> <ng-template [ngTemplateOutlet]="slow.tpl isFast"></ng-template> `, }) export class ConnectionComponent { isFast = true; @ContentChild(FastDirective

    2K30发布于 2019-11-06
  • 来自专栏前端侠2.0

    Angular中,父组件向子组件传递 “模版内容引用”

    一、如何组件自定义输入内容 比如在一个页面上,引用nz-card时,把页面上<ng-template>内容插入到nz-card中去, ? ngTemplateOutlet 完整示意-----我是主页 <app-content [dynamicRef]="usedByContent"></app-content> <ng-template

    主页面的变量绑定: {{valueInApp}}
    </ng-template>`, }) export class AppComponent

3.8K20发布于 2020-03-20
  • 来自专栏全栈修仙之路

    ng-content 中隐藏的内容

    The solution 为了让包装器能够控制其子元素的实例化,我们可以通过两种方式完成:在我们的内容周围使用 <ng-template> 元素,或者使用带有 “*” 语法的结构指令。 为简单起见,我们将在示例中使用 <ng-template> 语法,我们的新应用程序如下所示: <wrapper> <ng-template> <counter></counter> </ ng-template> </wrapper> 包装器不再使用 <ng-content>,因为它接收到一个模板。

    3.8K30发布于 2019-11-06
  • 来自专栏技术积累

    【转载】【ionic+angularjs】angularjs ui-router路由简介

    li>test

  • <script type="text/<em>ng-template</em> </script> <script type="text/ng-template" id="'page3.html'"> this is page 1 for test. </script> <script type="text/<em>ng-template</em>" id="'page2.html'"> this is page 2 for app. </script> <script type="text/<em>ng-template</em>" id="'page3.html'"> this is page 1 for test. </script> <script type="text/<em>ng-template</em>" id="'page4.html'"> this is page 2 for test.

    8.4K70发布于 2020-07-28
  • 来自专栏前端布道

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

    解决方法 为了让组件能够控制投射进来的子组件的实例化,我们可以通过两种方式完成:在我们的内容周围使用 <ng-template> 元素及 ngTemplateOutlet,或者使用带有 "*" 语法的结构指令 为简单起见,我们将在示例中使用 <ng-template> 语法。 show = true; constructor() { } ngOnInit() { } } 然后我们将 demo-child-component 包含在 ng-template 中: <demo-component> <ng-template> <demo-child-component></demo-child-component> </ng-template

    3.4K81发布于 2018-04-11
  • 第 2 页第 3 页
    点击加载更多
    领券