【发布时间】:2017-06-11 19:35:42
【问题描述】:
我刚刚开始学习 Angular 并陷入了这个问题。我在AngularJS : Why ng-bind is better than {{}} in angular? 上读到{{}} 和ng-bind 会给你同样的结果。但是,以下代码并非如此:
JS
(function () {
angular
.module("myApp", [])
.controller("selectCtrl2", function ($scope, $http) {
$http({
method: "GET",
url: "http://localhost/testService/name.php"
})
.then(function (response) {$scope.names = response.data.content;},
function (response) {$scope.names = response.statusText;});
});
})();
HTML
<body data-ng-app="myApp">
<div data-ng-controller="selectCtrl2">
<select>
<option data-ng-repeat="x in names">
<span data-ng-bind="x"></span>
</option>
</select>
</div>
</body>
ng-repeat 实际上创建了 3 个选项标签,但它们的 innerHTML 只是空格。 由于一些奇怪的原因,如果我使用 {{x}},它们的 innerHTML 将被我准备的数组中的文本填充 [a, b, c]。我想知道可能是什么原因。
【问题讨论】:
标签: javascript html angularjs ng-bind