Hi I'm a beginner at programming. I'm trying to put data from a json file into a variable
I want to have AngularJS put text into a html document like this
{{ data.text }}
And the text is based off of a json file I have in the app.js, so I set data using JQuery:
myApp.controller('Ctrl', function ($scope, $http) {
$.getJSON("../static/file.json", function(data) {
$scope.data = data;
});
But nothing shows up initially. When I log $scope.data, it turns out to be undefined. But I know that my json file is correct because if I put all this code in some method that is called like
$scope.foo = function(){$.getJSON("../static/file.json", function(data) {
$scope.data = data;
});}
and have some button activate this, it'll work fine. But I want this to be there initially.