javascript - AngularJs select add option -
i work angularjs , select options collection. if added in html option tags works good. if try added item angular not working.
my code:
<div ng-controller="statisticstablecontroller"> <select ng-model="publishersdata" ng-options="s 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 not working? , how 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 s in publishersdata" chosen option="publishersdata"> </select> </div>
it not working
try code instead of data use value in argument of foreach
angular.foreach(data, function (value) { publishersarray.push(value.name); });
Comments
Post a Comment