TemplateRef和ViewContainer在Angular 2中有什么不同
从我对文档和一些示例代码的理解来看,我意识到ViewContainer包含templateRef,而templateRef本身包含HTML。但我想知道进一步的解释: 我有如下问题:TemplateRef和ViewContainer在Angular 2中有什么不同,angular,templates,angular2-template,Angular,Templates,Angular2 Template,从我对文档和一些示例代码的理解来看,我意识到ViewContainer包含templateRef,而templateRef本身包含HTML。但我想知道进一步的解释: 我有如下问题: 他们每个人都在做什么 我们在布局中找到它们的频率是多少。每个都是 它们与HTML上的每个节点都关联 这也和路线有关吗 提前谢谢 Template Ref ViewContainerRef --------------------------------------
Template Ref ViewContainerRef
-----------------------------------------------------------------------------------
Represents an Embedded Template It is a continaer in which templates in
which one or more Views can be attached
Used for creating a custom structural Wrapper for holding the view
directive created using TemplateRef
Two ways to access Can attach views in 2 ways
- using * infront - using createComponent()
- using as a property binding - using createEmbeddedView()
回答你的第二个问题
- 我们没有创建结构指令的实践
- 因此,我们通常不会经常使用它
- 然而,我们使用的结构指令是使用这些类创建的