Currently diving into learning Angular and I have a question about how to replace a hardcoded JSON array with JSON retrieved using http get
. Here is the link to the plunker that I am actively working on. In order to populate the dropdown menu at the top, I am currently using this code:
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'm unsure if this is where I should be populating the array as well? Is this the correct approach or is there a better method to achieve this (similar to what I've done above)? Do I need to manually create an array for all objects or can I simply access the incoming JSON data. Thank you.