为什么 ng-bind 和 {{}} 为 json 提供不同的输出?

Why is ng-bind and {{}} giving different outputs for a json?

这是我正在使用的代码,不明白为什么 ng-bind{{}} 的输出不同。

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>

这是我得到的输出

//for ng-bind
[object Object]      

//for {{}}
{"foo":"ankur","bar":"23"}

原因是 {{}} 在将其绑定到视图之前评估表达式,而 ng-bind 没有这样做,所以你有一个字符串表示 数组对象。