我的 employee.json 文件与我的 Controller 位于同一目录中。
这是我的 json 文件中的数据:
["John", "Clark"]
在我的 Controller 上:
.controller('EmployeeCtrl', function ($scope, $http) {
$http.get('employee.json').then(function (res) {
$scope.contents = res.data;
});
});
在我的模板上:
<div>
<label class="control-label">Identify yourself:</label>
<select ng-model="market.name">
<option ng-repeat="content in contents" value="{{content}}">{{content}} </option>
</select>
</div>
有谁知道为什么这不起作用?我的下拉列表不显示任何内容。
最佳答案
.controller('EmployeeCtrl', function ($scope, $http) {
$http.get('employee.json').success(function (res) {
$scope.contents = response.data;
});
});
还要确保 JSON 文件中的数据格式正确。
关于javascript - 从 Controller 读取 JSON 文件并使用 ng-repeat 显示为 <li>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31817612/