Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
How does TemplateRef and ViewContainer differ in Angular 2

From my understanding of docs and few sample code, I realize that ViewContainer is something that holds a templateRef, while templateRef in itself holds the HTML. But I would like to know a further explanation:

I have questions like :

  1. What each one of them exactly does.

  2. How often do we find each one of them in a layout. Is each of them associated with every single node on my HTML.

  3. Has it something to do with routing as well

Thanks in advance

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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()

To answer your second question,

  • We don't have a practice of creating structural directives.
  • So, mostly we will not use it often.
  • However, the structural directives which we use ngIf, ngSwitch, ngFor are creating using these classes.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!