-
$implicit
有什么用? -
$implicit
和let-
之間是什么關(guān)系
我們可以通過let-name在ng-template上定義局部變量筋粗。該name字段只能在ng-template內(nèi)部使用嘹悼。
當(dāng)angular通過調(diào)用createEmbeddedView
創(chuàng)建模板時启具,它也可以傳遞將在ng-template中使用的上下文鄙麦。
使用鍵$implicit將設(shè)置上下文對象中的默認(rèn)值氓英。所以如果我們寫:
vcRef.createEmbeddedView(template, { $implicit: 'value' })
<ng-template let-foo>
{{ foo }}
</ng-template>
相當(dāng)于
<ng-template let-foo="$implicit">
{{ foo }}
</ng-template>
如果不使用$implicit
, 則需要這樣寫
vcRef.createEmbeddedView(template, { m: 'value' })
<ng-template let-foo='m'>
{{ foo }}
</ng-template>