Skip to content

Instantly share code, notes, and snippets.

@hahalin
Last active March 6, 2016 14:22
Show Gist options
  • Select an option

  • Save hahalin/1168f43c2bb80ba70711 to your computer and use it in GitHub Desktop.

Select an option

Save hahalin/1168f43c2bb80ba70711 to your computer and use it in GitHub Desktop.
angularjs populate select option data from ajax
var app = angular.module('BpmApp', [])
app.controller('regctrl', function ($scope, CompanyService) {
getCompanies();
$scope.selectedCompany = "1";
function getCompanies() {
CompanyService.getCompanies()
.success(function (ds) {
$scope.companies = ds;
})
.error(function (error) {
$scope.status = 'Unable to load company data: ' + error.message;
console.log($scope.companies);
});
}
});
app.factory('CompanyService', ['$http', function ($http) {
var CompanyService = {};
CompanyService.getCompanies = function () {
return $http.get('/Company/List');
};
return CompanyService;
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment