角度2中的$ implicit是什么? [英] What is $implicit in angular 2?

查看:591
本文介绍了角度2中的$ implicit是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

angular2 ng-templates中如何使用以下关键字

How is the following keyword used in angular2 ng-templates

  • 角度2模板中$implicit的目的是什么?
  • let-<attribute>$implicit之间是什么关系?
  • What is the purpose of $implicit in angular 2 templates?
  • What is relationship between let-<attribute> and $implicit?

推荐答案

您可以通过let-name

angular通过调用createEmbeddedView创建模板时,也可以传递将在ng-template

When angular creates template by calling createEmbeddedView it can also pass context that will be used inside ng-template

在上下文对象中使用键$implicit将其值设置为默认值.因此,如果我们写:

Using the key $implicit in the context object will set it's value as default. So if we write:

vcRef.createEmbeddedView(template, { $implicit: 'value' })

我们有模板

<ng-template let-foo> 
 {{ foo }}
</ng-template>

那么我们可以这样考虑

<ng-template let-foo="$implicit"> 
  {{ foo }}
</ng-template>

因此foo将等于value

柱塞示例

Plunker Example

另一方面,如果我们具有类似这样的上下文:

On the other hand if we have context like:

{ bar: 'value' }

我们必须像这样声明变量

we have to declare variable like:

let-foo="bar"

这篇关于角度2中的$ implicit是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆