0

for my example i took an image in the template:

<img class="cImg" (load)="onChange($event)" src="../../../assets/img/noob.jpg">

I would like to access to the element "path" from an even with angular I've read some other post about it, like: Angular - How do I parse the objects in inside event.path

or

How to get the height and width of an image in Angular 2(or above) from input tag before uploading it to the server without jQuery?

but none of this on work for me.

Event structure:

enter image description here

There is the code with the error I get with someway I've tried to use to get access to an element of the element "path"

enter image description here

Error:

enter image description here

I tried also to get it by the target, base on what I've read, with no success

Thanks for your help

2 Answers 2

1

You can override the type:

const paths = (event as any).path as HTMLElement[];

When you have the wanted item, if you want to get some style, you can achieve that doing so:

const style = this.windowRef.getComputedStyle(elem); // or window.getComputedStyle(elem)

Bu normaly, you can fetch clientHeight for example directly with elem.clientHeight.

This works: (event as any).path[0].clientHeight

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks you! The problem is I can't get other elements inside of "paths", like, example clientHeight. I thought by getting the path I could go under with forEach or path[0].clientHeight to get the size. but it doesn't work :(
There is something strange, if I do path[0].clientHeight I get 0 and in reality if I watch path[0] I see in the element clientHeight 400..... Maybe I'm drunk :D
I don't understand. Sometime it works, sometime not.... Do you have an idea where it cans come from ?
No, sorry, I have no idea
0

If you want to reach path property just use:

onChange($event) {
    console.log($event.path);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.