Recently, I started working with Angular 1.5+ and I'm facing some challenges with the basics, particularly when it comes to displaying data from a JSON file on the DOM.
Although I can fetch the data successfully (at least I think so, as it console logs without any errors)
I'm stuck on how to properly interact with the data in the controller so that it can be used in the HTML
Data Service
export default class Gsheets {
constructor($http){
'ngInject';
this._$http = $http;
var gData = this;
this._$http({
method: 'GET',
url: 'https://jsonplaceholder.typicode.com/posts',
})
.then(function(response) {
console.log(response.data);
gData.headers = response.data;
}, function() {
alert("Error");
});
}
}
Controller Setup
(What steps should I take here?)
class EditorCtrl {
constructor( Gsheets) {
'ngInject';
this._Gsheets = Gsheets;
}
}
HTML Integration
<ul>
<li ng-repeat="header in $ctrl.gData.headers"></li>
{{header}}
</ul>
Your assistance would be greatly appreciated. Thank you for your help.
Best regards,