Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TemplateRef和ViewContainer在Angular 2中有什么不同_Angular_Templates_Angular2 Template - Fatal编程技术网

TemplateRef和ViewContainer在Angular 2中有什么不同

TemplateRef和ViewContainer在Angular 2中有什么不同,angular,templates,angular2-template,Angular,Templates,Angular2 Template,从我对文档和一些示例代码的理解来看,我意识到ViewContainer包含templateRef,而templateRef本身包含HTML。但我想知道进一步的解释: 我有如下问题: 他们每个人都在做什么 我们在布局中找到它们的频率是多少。每个都是 它们与HTML上的每个节点都关联 这也和路线有关吗 提前谢谢 Template Ref ViewContainerRef --------------------------------------

从我对文档和一些示例代码的理解来看,我意识到ViewContainer包含templateRef,而templateRef本身包含HTML。但我想知道进一步的解释:

我有如下问题:

  • 他们每个人都在做什么

  • 我们在布局中找到它们的频率是多少。每个都是 它们与HTML上的每个节点都关联

  • 这也和路线有关吗
  • 提前谢谢

    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()
    
    回答你的第二个问题

    • 我们没有创建结构指令的实践
    • 因此,我们通常不会经常使用它
    • 然而,我们使用的结构指令是使用这些类创建的

    U所述ViewContainerRef通过createComponent附加视图。这是否意味着每个组件的模板也包装在ViewContainer中。我没有收到你的问题组件在@component decorator中提供了自己的模板。此模板是否也使用ViewContainerRef包装。