Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we use double braces for ng-src in AugularJS?

I'm confused about AngularJS expressions.

From w3schools.com, I learned that

  1. AngularJS expressions can be written inside double braces: {{ expression }}.
  2. AngularJS expressions can also be written inside a directive: 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?

like image 366
Galaxy Avatar asked Apr 08 '16 07:04

Galaxy


People also ask

Why we use double curly braces in angular?

Using the double braces: The double curly braces can be used to displays the content from the model to the view component.

What is double brackets in angular?

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.

What do double braces mean in HTML?

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.

How do you use double curly braces in HTML?

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.


1 Answers

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.

like image 74
Kutyel Avatar answered Oct 17 '22 17:10

Kutyel