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
16
votes
3 answers

bind #element to element created with *ngFor

I am using *ngFor to create a bunch of divs. I would like to get my hands on one of them and get its width. .html
sanjihan
  • 5,592
  • 11
  • 54
  • 119
16
votes
1 answer

Angular 4 cannot find name 'ViewChild'

I have this strange error and didn't find anything similar to it .. I'm using ng2-canvas-whiteboard component for a drawing canvas on my website, everything's working perfectly except when i try to get reference to that canvas using :…
Soufiane Touil
  • 803
  • 2
  • 8
  • 17
15
votes
3 answers

Expression has changed error on Opening a Modal Popup inside a component

I have a parent component and i am passing some HTML from it to a child common component using @ViewChild(). When Child component loads up a popup. Console throws below error. "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed…
Aakash Kumar
  • 893
  • 4
  • 15
  • 38
14
votes
3 answers

Angular 6 nested ViewChild inside ng-template is null

We are using a modal (ng-bootstrap's one) in our application. That modal looks like: And it's logic: @ViewChild('modal') modal: ElementRef; @ViewChild('audio') audio:…
Erwol
  • 1,911
  • 2
  • 23
  • 28
12
votes
2 answers

@Viewchild not initializing during ngOnInit

I'm running two MatTables in different components with data sources from different observables. One of my tables sort functionality is working fine and but on my second table it seems as if the @ViewChild for MatSort doesn't initialize during…
Timotronadon
  • 315
  • 1
  • 2
  • 15
12
votes
1 answer

angular 2 - How to get HTMLElement / ElementRef of child component using template reference variable?

I'm trying to get element of child component using ViewChild but can't find a way to achieve this. Let's say in template: ... ... and getting this reference by: import { SomeComponent } from…
Dangular
  • 389
  • 1
  • 3
  • 15
12
votes
4 answers

@ViewChildren does not get updated with dynamically added DOM elements

I have the following DOM structure
Giridhar Karnik
  • 2,213
  • 4
  • 27
  • 47
12
votes
3 answers

Angular2 -- @ViewChild from TypeScript base abstract class

I was looking @ this SO Q & A, and wondering if it was possible to have a base abstract class instead? Rather than an interface, is it possible to have differing implementations of a base class in child components that are accessible to the parent…
David Pine
  • 23,787
  • 10
  • 79
  • 107
11
votes
2 answers

Cannot read property 'native-element' of undefined Angular 8

after my angular application versions upgrade from angular 7 to angular 8 i run into a complication problem with rows like this export class followupComponent implements OnInit { @ViewChild('message') messageElement: ElementRef; …
Stack Overflow
  • 2,416
  • 6
  • 23
  • 45
11
votes
5 answers

@Viewchild can not see matSort

In my Angular application, my @ViewChild instance is failing to fill HTL matSort. mycomponent.ts: import { MatSort } from '@angular/material'; export class MyClassComponent { @ViewChild(MatSort) sort: MatSort; } ngOnInit() { …
11
votes
3 answers

Angular, get ViewChild / ViewContainerRef from dynamic created Component

is there a way to get the ViewContainerRef from a dynamic created component? My dynamic created component has an ngContent element inside, which i want to fill after the dynamic creation. export class Example { @ViewChild('content', { read:…
Hemant Desusa
  • 181
  • 2
  • 6
10
votes
1 answer

Angular2 - Directive not working when not declared in the same module

I have a directive and I want to use it in multiple modules. Declaring it on each modules produces an error. Thus, I tried to declare it in a shared module and import this shared module to other modules. However, it didn't work. It only works when…
9
votes
2 answers

How to Unit test the @viewChild ElementRef angular

My component file has the following code @ViewChild('clusterCard', { static: false }) clusterCard: ElementRef; highLightTheClusterCard(point: PickupClusterPoint) { if (point) { const card: HTMLElement = _get(this.clusterCard,…
sunil
  • 660
  • 8
  • 20
9
votes
3 answers

viewchild input property not updated when needed angular 2

I have been looking for some reason of this behavior, the value of a Input() property in a child component 'Param' is not been updated at the right time, I need to use the updated value to call a service as a parameter. By clicking the 'update child…
destined
  • 324
  • 1
  • 3
  • 9
8
votes
4 answers

ngx-datatable - custom columns with action buttons

I have a table (ngx-datatable) in which I want to define an "actions" column in which buttons will then be placed for CRUD operations. Creating the column and placing the buttons worked, but I have the problem that the selected row and the values…
Codehan25
  • 2,704
  • 10
  • 47
  • 94
1
2
3
29 30