加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何从* ngIf将上下文传递给Angular 5模板

发布时间:2020-12-17 18:11:07 所属栏目:安全 来源:网络整理
导读:Angular的 NgTemplateOutlet允许您将上下文传递到出口以进行属性绑定. ng-container *ngTemplateOutlet="eng; context: {$implicit: 'World'}"/ng-containerng-template #eng let-namespanHello {{name}}!/span/ng-template Angular的* ngIf允许您根据布尔条
Angular的 NgTemplateOutlet允许您将上下文传递到出口以进行属性绑定.

<ng-container *ngTemplateOutlet="eng; context: {$implicit: 'World'}"></ng-container>
<ng-template #eng let-name><span>Hello {{name}}!</span></ng-template>

Angular的* ngIf允许您根据布尔条件嵌入一个或另一个模板:

<ng-container *ngIf="isConditionTrue; then one else two"></ng-container>
<ng-template #one>This shows when condition is true</ng-template>
<ng-template #two>This shows when condition is false</ng-template>

如何将上下文传递给* ngIf语法中引用的这些模板?

解决方法

实际上你可以输入你的条件到ngTemplateOutlet(并摆脱ngIf).

<ng-container *ngTemplateOutlet="condition ? template1 : template2; context: {$implicit: 'World'}">
</ng-container>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读