I am stuck. Somehow I can't get this working. I try to load data for a web-app from a (still local) JSON-file. A section of this JSON contains colors and looks like this:
{
"colors" : {
"1" : "yellow",
"2" : "green",
"3" : "red"
},
"stuff : {...}
}
I have a very basic HTML file with some header stuff. Scipts are loaded in the header. The interesting part looks like this:
<ul ng-controller="ColorController">
<li ng-repeat="(key,value) in colors" value="{{key}}">
{{key}}: {{value}}
</li>
</ul>
The corresponding Javascript:
var colors = {
"1": "lyellow",
"2": "lgreen",
"3": "lred"
};
var app = angular.module('test', []);
app.controller('ColorController', function($scope){
$scope.colors = colors;
$.getJSON('data.json')
.then(function(res){
$scope.colors = res.colors;
});
})
I tried with a local version of colors first, therefore the variable colors. That worked well and produced the desired output. The I tried to switch to a local stored JSON. console.log showed a correct parsing. On a debug console, colors and res.colors looks the same. But the list on the page is not updated.
I'd guess it is something with timing, but I am not sure. Could somebody point me in the right direction?