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.
My code:
<div ng-controller="statisticsTableController">
<select ng-model="publishersdata"
ng-options="s for s in publishersdata"
chosen option="publishersdata">
</select>
</div>
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?
UPDATE
After changes:
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>
It is not working properly
ng-modelname.ng-modelandng-optionsarray name are same, change one of them. this may cause problems.