Working on learning some Angular and I was wondering how I could replace this hardcoded JSON array to the JSON that is pulled with the http get
. Here is the plunker im working on. At the top I do this to populate the dropdown i'm using:
angular.module('myapp', [])
.controller('MainCtrl', function($scope, $http) {
var records;
$scope.selCountry = '';
$scope.searchText = '';
$http.get('http://www.w3schools.com/angular/customers.php').success(function(dt) {
//window.alert(angular.toJson(dt));
var countries = [];
records = dt.records;
dt.records.forEach(function(o) {
var c = o.Country;
if (countries.indexOf(c) == -1)
countries.push(c);
});
$scope.countries = countries;
$scope.total = countries.length;
});
I don't know if this is where I would fill the array as well? Or is it even done like that (like I did above). Do I have to create the array for all objects or can I just access the incoming JSON. Thx.