0

I'm new in Angular 1.5+ and I'm having some small issues with the basics, such as displaying data from a JSON file on the DOM.

So, I'm able to fetch the data fine, (I think, since it console logs okay)

But, then I'm not too sure how to interact with it on the controller, so that it's used on the html

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

(What do I have to do here?)

class EditorCtrl {
  constructor( Gsheets) {
    'ngInject';


    this._Gsheets = Gsheets;
    }
}

HTML

       <ul>
         <li ng-repeat="header in $ctrl.gData.headers"></li>
         {{header}}
       </ul>

Thank you in Advance, and any help will be much appreciated.

Regards,

1 Answer 1

2

You store the response headers in a member of the Gsheets instance and the Gsheets instance as _Gsheets in the EditorCtrl.

So you need to reference it like this:

<ul>
  <li ng-repeat="header in $ctrl._Gsheets.headers">{{header}}</li>
</ul>
Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic, thank you very much sir, I thought it had something to do with the controller, instead of the html elements. Thank you for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.