Dependency injection 角度2指令语法

Dependency injection 角度2指令语法,dependency-injection,angular,Dependency Injection,Angular,是否有人可以从外部模板(未在组件装饰器内联声明)中澄清此语法(特别是*mycomponent): 事实上,*字符是应用结构指令的方式,是以下内容的快捷方式: <template mycomponent> <my-component></my-component> </template> 要应用此指令,您需要使用要使用它的组件的directives属性来定义它 这样的指令将以这种方式执行。参见NgIf one的示例: 具体来说,您可以

是否有人可以从外部模板(未在组件装饰器内联声明)中澄清此语法(特别是*mycomponent):


事实上,*字符是应用结构指令的方式,是以下内容的快捷方式:

<template mycomponent>
  <my-component></my-component>
</template>

要应用此指令,您需要使用要使用它的组件的directives属性来定义它

这样的指令将以这种方式执行。参见NgIf one的示例:

具体来说,您可以注入相应的TemplateRef和ViewContainerRef来管理关联模板的内容。在NgIf指令的上下文中,它只是在DOM中呈现或不呈现该内容

有关结构指令的更多详细信息,请参见本Soc:


您可以通过阅读来理解这一点,谢谢!我在找那个。谢谢你的帮助!同一套西装不适合我不知道为什么请看这个
@Component({
  selector: 'my-component',
  directives: [SubComponent],
  template: `
    ...
  `
}) 
<template mycomponent>
  <my-component></my-component>
</template>