After the OP explained what exactly was the problem.
So, the question here is very simple: when do we use {{}}
and when we don't in the context of ng-model
.
When you do a <input type=... ng-model="someModel>
, what you're essentially telling Angular is: "Here is an input element; attach $scope's someModel
variable to the value of this input element.
Now, you can use this in your JavaScript controller like so: $scope.someModel
, but what about HTML? We have a templating language in Angular, and when you give it some variable (say someModel
), it'll search its $scope
for it, and then put in the value there. If it is unable to, it'll throw a nasty error.
In essence, {{}}
GETS the value, without that, you generally set the variable to gold the value of something.
Very simply put, AngularJS thinks that the content within the brace is an expression, which must be resolved. Once it is, Angular puts the value of the resolved expression there. In the most basic of the terms, you just tell it: "Here is some expression; put the evaluated value instead."
In ES6, we call it template strings
.
So, you'll use it for expressions which mutate after every iteration. Say, a loop or something. Places where you know what the answer is, or you have static content, you won't use it.
Say you have the following bit of code:
...
...
$scope.figureOne = 10;
in your controller.js
and the following in its view file:
<div>My age is {{ figureOne }}</div>
Angular gets the value from the $scope
, and puts it there; so, the rendered form will be: My age is 10
. However, if you had the following
<div>My age is figureOne</div>
This time, Angular knows that there is nothing to evaluate or resolve, so, it'll just render it as it is: My age is figureOne
.
I hope I made it clear! :)