#how can I get src value from img in my component.ts file

4 messages · Page 1 of 1 (latest)

fading kernel
#

Hey I would like to get the src value from img html in my component.ts file to split the url and use data as i want, is it possible ? How ?

Thanks

short depot
#

When using Angular, the HTML is generated based on the model. So the src should come from some data in your TypeScript code already.

sudden surge
short depot
#

But why, when you could simply do

@Component({
  template: '<img [src]="imageUrl"/>'
  // ...
})
class MyComponent {
  imageUrl = 'https://example.com/my-image.jpg';
}