I'm confused about AngularJS expressions.
From w3schools.com, I learned that
{{ expression }}
.ng-bind="expression".
But why do we use ng-src={{...}}
instead of ng-src="..."
?
Is the ng-src
a special case when dealing with AngularJS expressions?
Using the double braces: The double curly braces can be used to displays the content from the model to the view component.
Interpolation in Angular In simple terms, when you send data from an Angular component to the template using the mustache syntax or what you would call double curly brackets (these: “{{ … }}”) it is called interpolation. You can use it with variables, objects and even functions.
Template Values {}The double curly brackets are not HTML but scripting code. The term inside, interest, is a placeholder, sort of like the name and address in a form letter. The string {{interest}} will be replaced when the HTML template is converted into straight HTML that is sent over the network to the user.
Declare a template in the HTML file. Handlebars expressions are put into double curly braces {{expr}} for HTML-escaped content; otherwise, use triple curly brackets {{{expr}}} to avoid HTML-escaping.
Yes, it is a special case for ng-src
, as it is waiting for a template
parameter, which is a string
with any kind of interpolation inside ({{}}
), as stated in the docs.
<img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />
This depends on how the directive is specified by itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With