First time trying to get json data and bind it to my form using AngularJS. I am able to bind the json this way but it requires I manually match "data" to each of my items in my html.
http call from my controller:
$http.get('static.json').
success(function(data, status, headers, config) {
// here I have to manually copy all my json to bind with "data"
$scope.SiteID = data.SiteID;
$scope.SiteCode = data.SiteCode;
}).
error(function(data, status, headers, config) {
// log error
});
My json:
{
"SiteID":"mySiteIDGoesHere",
"SiteCode":"mySiteCodeGoesHere"
}
Is there a way to automatically bind my json without having to go through each item manually? eg:
$http.get('static.json').
success(function(data, status, headers, config) {
"just pull in whatever my json is and bind it"
$scope.WhateverIsInJSONID = data.WhateverIsInJSONID;
$scope.WhateverIsInJSONCode = data.WhateverIsInJSONCode;
}).
error(function(data, status, headers, config) {
// log error
});
$scope.something = dataand then your views will be like:{{something.WhateverIsInJSONID}}, or whatever