填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

NgTemplateOutlet

根据一个提前备好的 TemplateRef 插入一个内嵌视图。

Inserts an embedded view from a prepared TemplateRef.

查看"说明"...

Exported from

选择器

属性

属性说明
@Input()
ngTemplateOutletContext: Object | null

附加到 EmbeddedViewRef的上下文对象。这应该是一个对象,该对象的键名将可以在局部模板中使用 let 声明中进行绑定。在上下文对象中使用 $implicit 为键名时,将把它作为默认值。

A context object to attach to the EmbeddedViewRef. This should be an object, the object's keys will be available for binding by the local template let declarations. Using the key $implicit in the context object will set its value as default.

@Input()
ngTemplateOutlet: TemplateRef<any> | null

一个字符串,用于定义模板引用以及模板的上下文对象。

A string defining the template reference and optionally the context object for the template.

说明

你可以通过设置 [ngTemplateOutletContext] 来给 EmbeddedViewRef 附加一个上下文对象。 [ngTemplateOutletContext] 是一个对象,该对象的 key 可在模板中使用 let 语句进行绑定。

You can attach a context object to the EmbeddedViewRef by setting [ngTemplateOutletContext]. [ngTemplateOutletContext] should be an object, the object's keys will be available for binding by the local template let declarations.

      
      <ng-container *ngTemplateOutlet="templateRefExp; context: contextExp"></ng-container>
    

在上下文对象中使用 $implicit 这个 key 会把对应的值设置为默认值。

Using the key $implicit in the context object will set its value as default.

例子

Example

      
      @Component({
  selector: 'ng-template-outlet-example',
  template: `
    <ng-container *ngTemplateOutlet="greet"></ng-container>
    <hr>
    <ng-container *ngTemplateOutlet="eng; context: myContext"></ng-container>
    <hr>
    <ng-container *ngTemplateOutlet="svk; context: myContext"></ng-container>
    <hr>

    <ng-template #greet><span>Hello</span></ng-template>
    <ng-template #eng let-name><span>Hello {{name}}!</span></ng-template>
    <ng-template #svk let-person="localSk"><span>Ahoj {{person}}!</span></ng-template>
`
})
export class NgTemplateOutletExample {
  myContext = {$implicit: 'World', localSk: 'Svet'};
}
    

方法

      
      ngOnChanges(changes: SimpleChanges)
    
参数
changes SimpleChanges