我angularjs和选择选项收集工作。如果我在HTML中的选项标签添加的所有作品不错。但如果我尝试从角添加的项目它不工作。
I work with angularjs and select options collection. If I added in html option tags all works good. But if i try added item from angular it is not working.
我的code:
<div ng-controller="statisticsTableController">
<select ng-model="publishersdata"
ng-options="s for s in publishersdata"
chosen option="publishersdata">
</select>
</div>
和AngularJs code:
and AngularJs code:
function statisticsTableController($scope, $http) {
var publishersArray = [];
$http.get('/api/getAllItems').success(function(data) {
angular.forEach(data, function(data) {
publishersArray.push(data.Name);
});
});
this.publishersdata = publishersArray;
//...
}
为什么它不工作?而如何解决?
Why it is not working? And how to fix it?
更新
在变化:
function statisticsTableController($scope, $http) {
var publishersArray = [];
$http.get('/api/getAllItems')
.success(function (data) {
angular.forEach(data, function (data) {
publishersArray.push(data.Name);
});
});
$scope.publishersdata = publishersArray;
//...
}
HTML
<div ng-controller="statisticsTableController">
<select multiple
ng-model="publishersdata"
ng-options="s for s in publishersdata"
chosen option="publishersdata">
</select>
</div>
它不能正常工作
试code,而不是数据的使用价值中的foreach参数
try the code instead of data use value in argument of foreach
angular.forEach(data, function (value) {
publishersArray.push(value.Name);
});