Questions tagged [elementref]
78 questions
0
votes
1 answer
How to set classes for an HTML reference from within the HTML code Angular?
I have a reference to a textarea
<*wrapper-component (submit)="tx1.value ? submit(tx1.value) : tx1.setClass('required')??">

Steve Chacko
- 95
- 11
0
votes
1 answer
How to measure element width of an HTML element in Angular?
I want to dynamically create an element and then get its clientWidth. The code snippet looks like this using the regular DOM API.
HTML Snippet:
The element has its css property visibility set to 'hidden'.…

Eddie Lam
- 579
- 1
- 5
- 22
0
votes
1 answer
Error when trying to use ViewChild annotation in Angular
I am trying to use ViewChild like this:
@ViewChild('hello', { static: false })
divHello?: ElementRef;
This is the template:
Some test data
But, the ViewChild annotation is showing this error:
Unable to resolve…
joler-botol
- 442
- 1
- 7
- 22
0
votes
1 answer
Error with ElementRef angular unit test with Jest
I have an error when I run the unit tests with Jest, I have component for an application in Angular, when I have in the constructor 'ElementRef', it throws the following error:
Incrementador Component › should create
Can't resolve all parameters…

mpuertao
- 21
- 4
0
votes
0 answers
Angular type error: getBBox() is not a function on ElementRef
I am calling this.container.nativeElement.getBBox() in ngAfterViewInit — as you can see in the screenshot, this is causing an error and getBBox() is supposedly not a function. The strange thing is that getBoundingClientRect() works just fine on the…

tarana
- 3
- 2
0
votes
1 answer
Detect Click Outside of Element Angular 9 - Multiple Instances
In my app, on click of an element I am showing a tooltip that contains additional information. This is available for all elements in a list. I would like to be able to close the expansion on click of anything outside of the tooltip.
The concept is…

ChocolateOrange
- 25
- 8
0
votes
1 answer
How to change bootstrap carousel items Angular
I have 4 images and when I click and the images I want the carousel to navigate to that respective index. Since bootstrap's carousel works with jquery and this is an Angular application, I am using elementRef to select the carousel component.…

Jonathan
- 441
- 1
- 9
- 28
0
votes
1 answer
How to search for selected checkbox in an divsion using elementRef in angular
Hi i am trying to make dynamic filter option that renders the property with their values on the basis of data entered by backend. On selecting value i want to fetch the checked values and pass it to backend for filtering. I am able to display the…

Santosh Upadhyay
- 79
- 1
- 9
0
votes
1 answer
Dynamic component loader - Cannot read property 'viewContainerRef' of undefined
im following all steps of the ad-banner tutorial on Angular.io. But at the end after all setup, i get an error comming from this component and function:
Ad-banner.component TS
loadComponent() {
this.currentAdIndex = (this.currentAdIndex + 1) %…

Mellville
- 1,027
- 2
- 18
- 39
0
votes
1 answer
How to get selected option using ElementRef?
I have a table where i can add dynamic rows to the table using ADD button.
To construct this table i have taken form array.
Each row is having a select box with list of options
scenario
once the user selected a option from select box and when he…

Bikshu s
- 389
- 4
- 14
0
votes
1 answer
Get ElementRef from component instance
On my Angular library I have a code similar as below:
test.component.html:
my-component.component.ts:
import { Component, Input,…

rubinhos
- 77
- 7
0
votes
1 answer
Ionic 4 - getting ElementRef property on Directive
I need get ElementRef value in a Directive to apply dynamically a class to the element.
My Directive:
import { Directive, ElementRef, Renderer2 } from '@angular/core';
@Directive({
selector: '[scrolling]'
})
export class ScrollingDirective {
…

Diego Roque
- 75
- 1
- 6
0
votes
0 answers
How to send data from child to parent using ElementRef and resolveComponentFactory in Angular?
The childbox which I create from inside the parent on the fly contains a close button which triggers a close function which is actually an EventEmitter whom message should reach the parent somehow in order to destroy the child component with…

a a
- 49
- 1
- 6
0
votes
1 answer
InnerHtml of elementRef of component created dynamically by componentFacory not containing binded values
I have a simple component named component1:
This is its HTML with the bindings and with the template reference:
This is…
{{someNumber}}

Guy E
- 1,775
- 2
- 27
- 55
0
votes
1 answer
How to get the children width from a htmlelement (elementref)
I need to get the width of all children from a elementref.
The items are dynamically loaded
Typescript:
@ViewChild('mainSubMenu') subMenu: ElementRef;
ngAfterViewInit() {
const greedyNav = this.subMenu.nativeElement;
let totalSpace = 0;
…

Babulaas
- 761
- 3
- 13
- 47