Jose Cerejo
Jose Cerejo

Reputation: 231

JSON returning [object Object] angularjs

I am trying to return the JSON data from the specified URL but when the alert pops up it just shows [object Object]. I intend that the date appears in the calendar but only on the day you enter the json and not on all days.. How do I do this?

My calendar

enter image description here

Here is an example of the JSON.

 {
    "title": "example glossary",
    "start": "2016-10-22",
    "allDay": false
}

controller

$scope.setDayContent = function(date) {

    return $http     ({
        method : "GET",
        url : "app/components/home/controller/test_calendar.json"
      }).then(function mySucces(response) {
          return response.data;              
        }, function myError(response) {
          $scope.valor = response.statusText;
      }); 

}; 

If i put it like this, it works fine <p>A data {{valor.start}}</p> but what I want is to appear on the calendar and then the error appears [object Object].

Upvotes: 0

Views: 4156

Answers (3)

Tim Consolazio
Tim Consolazio

Reputation: 4888

I'm not sure what you mean by this: "I intend that the date appears in the calendar but only on the day you enter the json and not on all days."

Where are you entering the JSON (that's probably not what you mean, but that's what it seems to say).

Then you say "if I do it this way it works..." but what appears to be working is that your call resulted in an error.

Also, "valor" is in your error message. I assume you don't want to display the error message in the calendar.

If I had to guess, I would say that you are probably binding the entire returned object in your Succes (hopefully that's just a spelling error in your example here) into your template, something like {{theObj}}, instead of the specific value you want, like "{{theObj.date}}" or some such.

(BTW I understood fine what you meant by "this is my JSON".)

Upvotes: 0

Fida
Fida

Reputation: 1358

   var data = {
        "title": "example glossary",
        "start": "2016-10-22",
        "allDay": false
    }
var json = JSON.stringify(data);
alert(json)

{
    "title": "example glossary",
    "start": "2016-10-22",
    "allDay": false
}

This is not JSON, this is JS object Literal.

to make it json.

    var data = {
        "title": "example glossary",
        "start": "2016-10-22",
        "allDay": false
    }
var json = JSON.stringify(data);

Upvotes: 1

Joao Polo
Joao Polo

Reputation: 2163

try to set the values at onSuccess function:

$scope.setDayContent = function(date) {
    return $http     ({
        method : "GET",
        url : "app/components/home/controller/test_calendar.json"
    }).then(function(response) {
        $scope.valor = response.data;
    }); 
};

Upvotes: 0

Related Questions