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
1 answer

Why is async function causing ViewChild to be undefined in ngOnInit()

Here is by Component which has a ViewChild referring to #h1 in the html: import { Component, ElementRef, ViewChild } from '@angular/core'; @Component({ selector: 'app-root', template: `

Welcome to {{title}}! …

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71
3
votes
1 answer

How to pass template variable to component without ViewChild

I need to pass a component A to another component B. Component B needs access to the nativeElement of A. I managed to get it to work like this: Container Template
Daskus
  • 929
  • 1
  • 10
  • 25
3
votes
1 answer

angular 2 re-render parent component from @ViewChild Component

I am working on angular2 application where I have parent component that pops up a child component @ViewChild(childPopupComponent) case: childPopupComponent; What I want to do is: when pressing save button from the child component (which is popup…
sockeros
  • 33
  • 3
3
votes
1 answer

Update innerhtml of element using viewchild in angular 2

I have html element like
title
I access the element in component using @ViewChild('hiddenElement') hiddenElement: ElementRef; How do i update the…
Hacker
  • 7,798
  • 19
  • 84
  • 154
3
votes
1 answer

What's the 'Angular way' of a child updating a parent?

There seems to be a few ways of skinning this cat, but I want to know the best (practice) and why. If I want to collect some data in child-cmp and pass it to parent-cmp, I can: Wrap an object with a function from parent and pass it as an input…
Ben Taliadoros
  • 7,003
  • 15
  • 60
  • 97
3
votes
1 answer

Template parse errors: Reference "#XXX" is defined several times in angular

I want to use the same name of template reference variables for querying at @ViewChildren. Metadata Properties: selector - the directive type or the name used for querying. read - read a different token from the queried elements. But, I got a…
niaomingjian
  • 3,472
  • 8
  • 43
  • 78
3
votes
3 answers

Ionic 2: How to call parent page function from Popover component

I have a page component with a button that opens a PopoverController. According to the Ionic Docs, popovers need another specific component for its content. In the main page I have a function that I need to call from the popover component, but I…
Àlex P
  • 33
  • 1
  • 3
3
votes
1 answer

Angular2 View Child Undefined Error

I'm trying a very simple example of calling childMethod inside the child component from the parent component via @ViewChild() decorator. Unfortunately, the ViewChild variable is always undefined. Child Component import {Component, Input, Output,…
Ankit Tanna
  • 1,779
  • 8
  • 32
  • 59
2
votes
1 answer

how to access a directive from another peer component

I have a component and a directive inside a parent component. The parent component template looks like this:
Is there a way to get a…
2
votes
1 answer

Angular: ViewChild undefined in modal/ ngTemplate

I am using the ViewChild to access a component within a modal (I used ngTemplate), but it is always set to "undefined" and therefore I cannot access its methods ... I call the function openModal and "paginatorComponent" is undefined. I've tried also…
2
votes
0 answers

Angular12 @ViewChild within two ngIf

I'm having problems using @ViewChild because it is nested within two different ngIf. My template looks something like this:
Timo Löhr
  • 21
  • 1
2
votes
2 answers

Angular: Access elementRef inside an ng-template

I got a component that renders different form-field components via ng-template. Now I want to access a function inside the last rendered component. I tried accessing it with the ViewChildren() annotation with the string selector or the BaseClass all…
KastenBrot
  • 87
  • 2
  • 13
2
votes
0 answers

Static @ViewChildren

I have a situation where I was to replace @ViewChild(Foo, { static: true }) foo!: Foo; with a version that gets several Foo in a list. The expected solution is @ViewChildren(Foo, { static: true }) foos!: QueryList; but @ViewChildren doesn’t…
KRyan
  • 7,308
  • 2
  • 40
  • 68
2
votes
4 answers

How to get a value from a stylesheet into the code so that it can be used programmatically?

I'm working on an Angular 8 app, and we use global styles. I'm using the D3 chart library in the app and to set a style, you have to configure it in code. For example: plottingArea.append('text') .attr('fill', '#00B2B3'); This will change the…
u84six
  • 4,604
  • 6
  • 38
  • 65
2
votes
2 answers

Angular viewChild get offset width

Angula 11 // REMARK THIS HAPPENS WITH ALL THE OFFSETS BUT GET THE ID PER EXAMPLE WORKS So we have a few @Viewchilds of ElementRefs that we want to get the offsetWidth. To do that we have the following code: // container is the REF that has the HTML…
mmonteirocl
  • 382
  • 2
  • 16