Questions tagged [viewchild]

ViewChild is a decorator for Angular component variables, which allow to bind a template element.

ViewChild is a decorator for Angular component variables, which allow to bind a template element. Official Angular documentation here: https://angular.io/api/core/ViewChild.

437 questions
3
votes
2 answers

@ViewChild - initializer error on Angular 13

I am creating app in Angular 13. I want to call the method show() of ChildComponent from ParentComponent, using @ViewChild, but I get errors. The older questions and answers are not working in this case. Parent:
Weronika
  • 370
  • 1
  • 4
  • 16
3
votes
2 answers

Angular 12: ViewChild not working for ElementRef inside modals

I have modal on which I am searching location using google map services. I am getting error of TypeError: Cannot read properties of undefined (reading 'nativeElement') HTML
ganesh
  • 416
  • 1
  • 11
  • 32
3
votes
2 answers

ViewChild from ngTemplateOutlet coming from parent component

I have a child component which accept a TemplateRef as an @Input and displays it through ngTemplateOutlet. How can I use @ViewChild/@ViewChildren to retrieve components inside the template ? If the template is declared in the same component that…
MHogge
  • 5,408
  • 15
  • 61
  • 104
3
votes
1 answer

Can we use @viewChild in @Injectable service in Angular10

I have below code working before Angular 10 upgrade ie., Angular 8. @viewChild in @injectable was working in Angular8 but not in Angular10 any reason ? Code below is the sample (below is how my existing code looks): @Injectable() export abstract…
Pradeep
  • 1,192
  • 2
  • 12
  • 30
3
votes
2 answers

Why I can't access to @ViewChild reference of a div defined in another component (not a subcomponent) in this example?

I am finding some problem trying to use @ViewChild() decorator. I will try to explain in details what I am trying to do. I have a correctly working version of my project (at the moment it is just a minimal prototype on which I am working on), in…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
3
votes
2 answers

Why @ViewChild() decorator is not working in this Angular component using PrimeNG FullCalendar?

I am finding the following problem working on a simple Angular 9 project that uses PrimeNG FullCalendar component, this one: https://primefaces.org/primeng/showcase/#/fullcalendar This PrimeNG FullCalendar component is based on this other Angular…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
3
votes
1 answer

Angular 8 - @ViewChild returns undefined on parent component. (no nested ngIf and called in ngAfterViewInit)

Hope someone can enlighten me. Problem I need to get a reference to a directive placed inside an inner component. I'm using @ViewChild targeting Directive class, with {static:true}since it doesnt have to wait for state changes and use it later on…
chudix
  • 33
  • 3
3
votes
1 answer

ViewChild with Stepper ExpressionChangedAfterItHasBeenCheckedError Angular 8

I'm trying to use ViewChild to get a child component's attribute for the Stepper [completed] property, but I can't figure out how to fix the "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value:…
3
votes
1 answer

@ViewChild returns undefined Angular 8

For some reason my @ViewChild in my Angular 8 App does not work "undefined". I have defined it like this in html file:
user3477485
  • 123
  • 1
  • 8
3
votes
1 answer

Jasmin : How to mock @ViewChild component in Angular 8

i'm trying to test a component with child components which are also stored as @ViewChild project-estimation.component.ts import { Component, OnInit, ViewChild, AfterViewInit, OnDestroy } from '@angular/core'; import { ProjectCreateComponent } from…
LuftWaffle
  • 187
  • 1
  • 3
  • 19
3
votes
0 answers

How to get ViewContainerRef from a subset of @ViewChildren filtered by Directive (FormControlName)?

I'm trying to add a custom directive to the form tag and then get the inputs that use the directive formControlName to filter them by formControl and then add the mat error component dynamically to it. I've been looking for some solutions. The best…
HNL
  • 103
  • 13
3
votes
2 answers

How to dynamically name element in angular

I want to create components dynamically from an array. #cmp1, #cmp2, #cmp3 should be dynamic how can this be achieved componentList:…
Jaya Venkat
  • 65
  • 1
  • 6
3
votes
0 answers

Karma - mock attribute of child component in parent component spec file

In my code i want to write a test case for a function in parent component . since i am setting a value to an attribute in child component ,while running karma suite for parent comp i am getting an error like attribute (child component ) is undefined…
3
votes
3 answers

Dynamically add Component in angular 2/4

How can I add component dynamically? toolbar.component.ts: @Component({ selector: 'app-toolbar', template: '' }) export class ToolbarComponent { constructor() { } } section.component.ts: @Component({ …
bui quang huy
  • 153
  • 1
  • 2
  • 12
3
votes
2 answers

Angular - @ViewChild from My Module

my question is regarding Angular 2/4/5 module. Can't make @ViewChild work while using it from a module, the child is undefined. before I was using it as a simple component and it worked fine. *Tried @ViewChildren also... same code samples -…
Ben
  • 793
  • 2
  • 13
  • 29