美文网首页
Angular: ng-templates中的 $implici

Angular: ng-templates中的 $implici

作者: CK110 | 来源:发表于2017-12-06 21:45 被阅读335次
  • $implicit 有什么用?
  • $implicitlet-之间是什么关系

我们可以通过let-name在ng-template上定义局部变量。该name字段只能在ng-template内部使用。

当angular通过调用createEmbeddedView创建模板时,它也可以传递将在ng-template中使用的上下文。

使用键$implicit将设置上下文对象中的默认值。所以如果我们写:
vcRef.createEmbeddedView(template, { $implicit: 'value' })

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

相当于

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

如果不使用$implicit, 则需要这样写
vcRef.createEmbeddedView(template, { m: 'value' })

<ng-template let-foo='m'> 
 {{ foo }}
</ng-template>

Plunker Example

参考链接

相关文章

网友评论

      本文标题:Angular: ng-templates中的 $implici

      本文链接:https://www.haomeiwen.com/subject/intrixtx.html