Why do ng-bind and {{}} give different outputs for json?

Here is the code I use, I don’t understand why there is a difference in the output of ng-bind and {{}} .

 angular.module('Test', []); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="Test"> <input type="text" ng-model="foo.bar" /> <input type="text" ng-model="foo.baz" /> <p ng-bind="foo"></p> <p>{{ foo }}</p> </div> 

This is the result that I get

 //for ng-bind [object Object] //for {{}} {"foo":"ankur","bar":"23"} 
+7
javascript angularjs interpolation
source share
1 answer

The reason is that {{}} evaluates the expression before binding it to the view, and ng-bind does not, so you have a string representation of your array object.

+7
source share

All Articles