Questions tagged [elementref]
78 questions
1
vote
1 answer
If statement and ElementRef to change background color not working [Angular]
I'm trying to get the background of the text to be green if case 3 and "Accepted your offer" is printed. I want to use elementRef to access the DOM and javascript to add the background colour using if statement. I added the if statement at the back…
user14526302
1
vote
1 answer
How to use DOM click() in Angular using Renderer2
I have a method that gets invoked based on certain user action. In that method I am trying to download a file using this approach.
But I don't want to use/refer document object directly so I am using combination of Renderer2 and ElementRef. This is…

Aakash Goplani
- 1,150
- 1
- 19
- 36
1
vote
1 answer
Why cant @ViewChild run outside AfterViewInit?
so I am trying to do some events base on the scrolling of my Angular application.
I have a problem since I am trying to access a element in my HTML with the help of @ViewChild.
I can access the element inside ngAfterViewInit() but I can't access it…

Allamo Olsson
- 299
- 2
- 12
1
vote
1 answer
Angular - Append dropdown to div
I am trying to add dropdown to a div. The html code (dropdown is an example) is dynamic code. Even though on clicking it shows the dropdown button but the dropdown isn't working. Following is my code from component file
import { Component, OnInit,…

Saad Bashir
- 4,341
- 8
- 30
- 60
1
vote
1 answer
Angular: why value changes (using renderer2) doesn't trigger the events bind to that
Scenario:
check this stackblitz
when i change the input value by typing something, the (keyup), (change) and (ngModelChange) events all fire;
when i change the input value by renderer2, none of the events fire
what i want:
I want to…

Akber Iqbal
- 14,487
- 12
- 48
- 70
1
vote
1 answer
Access value of a hidden div from inside an angular app in an iframe
I need to get a value of strings in a hidden div from inside an angular app. Here is what I have:

AlreadyLost
- 767
- 2
- 13
- 28
1
vote
1 answer
Angular 4+ Detect click in Div or nested child Divs and distinguish from other outside Divs
I have seen many Angular 2 pages that loop through a hierarchy of nativeElements. They don't work in Angular 4, 5, ...
I need to add a directive to a "workspace" DIV. There will be other Divs that are parent of workspace and others are child DIVs…

Yogi Bear
- 943
- 2
- 16
- 32
1
vote
0 answers
Alternative to ElementRef - Angular
In my ng2 application, I am using an external library which hasn't exposed its HTML elements.
I am using it as:
Now when it renders…
Title
Content

Rahul
- 5,594
- 7
- 38
- 92
0
votes
3 answers
Using ElementRef with async pipe
In my html i have async pipe and ElementReference.
In ts iam setting data comes with async pipe to nativeElement.innerHTML but iam getting this on console.
Cannot read properties of undefined (reading 'nativeElement')
Html

wostory
- 23
- 7
0
votes
2 answers
Angular cannot loop a list of ElementRef
I have a list of ElementRef for all my inputs but when I try to add listeners to them it makes like textInputs is empty but it's not.
@ViewChildren('text_input') textInputs!: QueryList;
ngAfterViewInit(): void {
…

TDev
- 75
- 1
- 10
0
votes
1 answer
How to access the background color of a button in a directive?
I need to access the background color of a button in order to change the text color depending if it's bright or dark. I need to access it in a directive.
If I try to get it this way:
this.el.nativeElement.backgroundColor
The console log in…

Remi Duplan
- 3
- 1
0
votes
2 answers
ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement'): How do I resolve this?
The state of my current code is like this:
...
{{node.instanceName}}
…

GeekAndNerd223
- 121
- 7
0
votes
0 answers
What is the safest way to perform an event from code in Angular?
When some data arrives from an API I need to perform a click event in my Angular app. It has to be done from typescript code. I use a component from an external library and it is the only way to make it work as I need.
I used ViewChild as…
0
votes
0 answers
Get element by classname from one component for use in another component using Angular
I have a background image on a component however in another component when an item is clicked, I would like for the background image in the other component to shrink. The component is current not being picked up
Bg.html (The component with the…

A.Mac
- 203
- 3
- 19
0
votes
0 answers
Angular HtmlCollection displaying less items on console, whereas on expansion more items are displayed which could not be captured by code
strong textThere is a library which on reference dynamically create a table , i want to get the scrollheight of this table
But when I do:
console.log(this.ElByClassName.nativeElement.getElementsByTagName('tbody'));
is showing
and on displaying the…

Nidhi Sarupria
- 3
- 4