-
$implicit
有什么用? -
$implicit
和let-
之间是什么关系
我们可以通过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>