2
Enter the Dollar Amount  <br>
1--<input type="text" ng-model="dollar1"  ></input> <br>
2--<input type="text" ng-model="dollar2" ></input> <br>
3--Not Working-<input type="text"  ng-value="{{dollar1 * dollar2}}" ></input>    <br>
4--Working<input type="text"  value="{{dollar1 * dollar2}}" ></input>  <br>
5--Working<input type="text"  ng-value="dollar1 * dollar2" ></input> <br>

Although the 5th one works if we use ng-value without curly braces

  • 1
    It is as you said, most of the directives (ng-..) don't use the curly braces https://stackoverflow.com/questions/17878560/difference-between-double-and-single-curly-brace-in-angular-js/17879046#17879046 – Groben Feb 02 '17 at 11:03

1 Answers1

2

If you use the Angular-Directive ng-value, the expression passed in is treated as an Angular code which can directly interpret dollar1 and dollar2 as scope-variables. AngularJS will process the directive ng-value and will add/set the result in the value attribute of the correspondig input element.

Using the html-built-in attribute value, you will need to use the curly braces to inject Angular code. In this case AngularJS will just replace the expression {{dollar1 * dollar2}} to its result.

Your Not Working example is not working because the AngularJS-directive is already expecting some real program code which must not start with curly braces. It should directly start with interpretable code.