【发布时间】:2016-03-25 22:20:57
【问题描述】:
我的 ng-repeat 不起作用。我正在尝试使用它来遍历这个 JSON 对象 tags.tagNames。我知道 JSON 对象在范围内并且正在工作,因为它显示在 <select> 元素上方(查看屏幕截图)。关于它为什么不填充 <select> 选项的任何想法?
![截图][http://i.imgur.com/iHEMDbx.png]
Javascript
$http.get("getNames.php")
.success(function (response)
{
$scope.tags.tagNames = response.records;
});
$scope.tags =
{
repeatSelect: null,
tagNames: null
};
HTML
<label style = "margin-top :30px;" class="control-label">Search Note Tags: </label>
<br>
{{tags.tagNames}}
<select class="combobox form-control placeholder" class = "col-sm-6" ng-model = "tags.repeatSelect">
<option value="">Tags</option>
<option ng-repeat = "tag in tags.tagNames | orderBy: 'string'" value = "{{tag.string}}"> {{tag.string}} </option>
</select>
【问题讨论】:
-
您的代码正确且工作正常。看到这个plunker
-
你遇到了什么错误?
-
带有选项的 ng-repeat 有更好的替代方案。结帐ng-options
标签: angularjs json select angularjs-ng-repeat