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

85
Views
Angular Dynamic Component from another module

I have a problem when I access the directive via View Child, I get an error that it is undefined

  1. shared

    • filter-type
      • filter-type.component.ts
      • filter-type.component.html
    • nav
      • nav.component.ts
      • nav.component.html
      • nav.component.scss
  2. stats

    • cases
      • cases.component.ts
      • cases.component.scss
      • cases.component.html filter.directive.ts

Filter Directive

@Directive({
  selector: '[derFilterRef]'
})
export class FilterRefDirective {
  constructor(public containerRef: ViewContainerRef) {}
}

Cases Component HTML

<ng-template derFilterRef></ng-template>

Nav Component TS

@Component({
  selector: 'stats-nav-bar',
  templateUrl: './nav.component.html',
  styleUrls: ['./nav.component.scss']
})
export class NavComponent {
  @ViewChild(FilterRefDirective, { static: false }) refDir!: FilterRefDirective;

  constructor(private resolver: ComponentFactoryResolver) {}


  openStrokeFilter() {
    const modalFactory = this.resolver.resolveComponentFactory(FilterTypeComponent);
    console.log(this.refDir);
    this.refDir.containerRef.clear();
    this.refDir.containerRef.createComponent(modalFactory);
  }
}

Nav Component HTML

<button (click)='openStrokeFilter()' class='w-100'>Stroke Type</button>

I think it's about View Child because it returns undefined, because I'm not looking for it inside the component, but in another module

about 4 years ago · Juan Pablo Isaza
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!