Gabriela Mendes
Gabriela Mendes

Reputation: 301

Angular template variable undefined on other tag

I have this template on my angular v6.1 application:

enter image description here

But de video on the p tag comes undefined, but in the loadeddata function have the correct value. I have a ngFor loop to read images and videos, for the videos I need the duration, width and heigh for each one of them.

I can't see where I'm doing wrong.

stackblitz code

Upvotes: 0

Views: 1471

Answers (1)

Max Kurtz
Max Kurtz

Reputation: 478

Looks like we have asynchronous code here. Tag p get its data synchronously, but at the very beginning it is undefined. Then, when media has finished loading, video gets the data. That's why

the loadeddata function have the correct value

Here is the solution. The only drawback is that url of your video google chrome marks as suspicious, that's why metadata of the video can't be preloaded before you open the video in new tab.

Upvotes: 1

Related Questions