K
K
kovdimaleks72019-03-01 11:28:59
Angular
kovdimaleks7, 2019-03-01 11:28:59

What is the difference between img src and img [src] in Angular 7?

Good afternoon.
There is not much experience with the latest Angular yet. It was necessary to rewrite a piece of code
from angularJs to the new angular. I came across a line in html with an image, like img ng-src= ....
Which I, after searching on stackoverflow and googling, changed it to img [src] = "assets/....
But I couldn't get it to work! On the page the image was not displayed.I
managed to solve it by simply removing the attribute and writing it like this: img src = "assets/....
Everything worked.
I tried to find information on img [src], but in vain! Either he was looking badly, or he simply does not exist. Who knows, tell me if there is such a built-in attribute in the new angular, and if so, what is the difference between native src and angular [src] ?
I really want to figure it out!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2019-03-15
@svgaryaev

If we are talking about Angular (not angular.js), then there is no difference between [src] and src as tag attributes. They are processed differently: src="../path/img.png" - is processed as a normal string value; [src]="path" - treated as a cast of the variable value to a string value (this.path = "../path/img.png").
Emnip, you can write it like this src="{{ path }}". Possibly, but not welcome.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question