1

Title.

SO I have a Job List array that displays as a list in HTML.I can add jobs through the page. I am trying to persist data with a database so I am trying to retrieve it right now.

So here's my getJobs from database method in my main controller. I put it in my main method because it's a pretty simple app.

Anyways, I debug it and I see that response does get the information from the database. It returns an array from my collections. It only has one object so far and its attribute name is "MyName". I see it says response.data[0].jobs would be the array, but I tried to set this.jobs to that and it didn't work. It says "can't set jobs to undefined". It adds something to my array, but it doesn't show anything.

So I am asking. How do I specifically link the array and objects in it with its attributes from the database to my local array in the application. Let me know if you need clarification and thanks a lot for the help. Much, much appreciated. Thanks!

  //function using $http to get data from database
    this.getJobs = function() {
        $http.get("https://api.mongolab.com/api/1/databases/joblistdatabase/collections/jobs", 
             {params: {apiKey:"****************"}
        }).then(function(response){
            alert(response.data);
            this.jobs = response.data;
        },(function() {
            alert("error");
        }));
    };
  • To quickly explain the duplicate... the `this` inside the `then` callback is not the same `this` in reference to your controller. See the answers in the other post for a work-around. – Phil Feb 08 '17 at 02:39
  • thank you. my googling is weak I guess/didn't really know my problem. –  Feb 08 '17 at 05:13

0 Answers0