I've been reading tutorials on Angular and some people seem to be using following syntax within their templates ${ value }
it seems to produce similar value as simply using {{ value }}
so I started wondering why add the dollar sign? Is this done for some semantics or does it actually have its functionality?
This specifically means that if the value you are binding to the view is null then it should return null else the actual value, so that you dont get any issues while rendering the template.
The AngularJS ng-value directive is used to set the value attribute of an input element, or a select element. It is mainly used on <radio> and <option> elements to set the bound values when these elements are selected. It is supported by <input> and <select> elements.
The #name syntax is a template reference which refers to the html object, more information can be found on in the Angular docs: Angular template guide. The [(ngModel)] is setting two way binding on the elements value and assigning that to a variable.
You can declare variables in html code by using a template element in Angular 2 or ng-template in Angular 4+. Templates have a context object whose properties can be assigned to variables using let binding syntax. Note that you must specify an outlet for the template, but it can be a reference to itself.
${someVar}
is string interpolation from TS and is applied before the template is processed by angular.
{{someVar}}
is Angular template binding expression.
To complete what Günter said, the ${someVar}
corresponds to the string interpolation feature of ES6. This can be used within strings defined between the charater ` (back-tick). This also allows to define string on several lines.
Here is a sample
let someVar = '10';
let someString = `The value of someVar is ${someVar}`;
It's something that can be used outside Angular2 with ES6.
See this link for more details: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings.
Hope it helps you, Thierry
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