【发布时间】:2023-03-15 05:48:01
【问题描述】:
我想以 JSON 格式在服务器上下载响应,其中包含用于填充我的选择列表的属性。我想用 AngularJS 来做,我正在使用 Angular 2。 什么都没有出现,我认为问题出在我的属性 ng-repeat 上:
<div id="myDiv">
<div ng-app="d3DemoApp">
<div ng-controller="AppCtrl">
<div ng-repeat="n in filters track by $index">
{{n}}
</div>
</div>
</div>
</div>
这是我的控制器:
angular.module('d3DemoApp',[])
.controller('myCtrl',function($scope) {
$scope.notes = userService.getData();
//Create and append select list
var selectList = document.createElement("select");
selectList.setAttribute("id", "releaseFilter");
myDiv.appendChild(selectList);
selectList.setAttribute("class", "form-control");
selectList.setAttribute("onclick", "myFunction()");
//Create and append the options
for (var i = 0; i < $scope.notes.length; i++) {
var option = document.createElement("option");
option.setAttribute("value", array[i]);
option.text = $scope.notes[i];
selectList.appendChild(option);
}
});
这是应该下载响应的服务:
app.service("userService",["$http",
function($http) {
_this = this;
this.getData = function() {
},
$http.get('./dataOnServer.json'). // This adress is normally an HTTP adress which send me the JSON
success(function(data) {
return data;
});
}
]);
这是 Plunker 问题的在线示例:https://plnkr.co/edit/du7sU8bhg2G3X7HckbV9?p=preview
希望你能帮帮我,非常感谢!
【问题讨论】:
-
你的 Plunker 不工作。
-
是的,这是问题的在线示例。
标签: angularjs json angularjs-ng-repeat getjson