Sunday, 15 May 2011

angularjs - Angular.js promise returning [Object object] -


I am calling a promise that gives an object to the service but is lost in any way in the controller.

I'm calling from my controller:

  dataService.getSpanishOverviewByID (newItem, api). Then (getSpanishOverviewByIDSuccess) Hold (errorClallback);  

In my service it seems that everything is working properly:

  function getSpanishOverviewByID (newItem, api) {console.log (newItem + "/" + Api); Return $ http ({method: 'GET', url: '/ api /' + api, newItem: newItem}). Then (getSpanishByIDSuccess) Grab (sendGetVolunteerError); } GetSpanishByIDSuccess function {var log = []; Angular.forEach (response.data, function (item, key) {console.log ('I found this!' + Response.config.newItem + "" + item.title); if (item.title == response.config .newItem) {console.log ('mailing' + object), this .push (item);}}, log); Console.log (logs); Return log; }  

console.log (log) returns an object: Enter image details Here

For some reason this does not cross the controller correctly:

  function getSpanishOverviewByIDSuccess (data) {$ rootScope.newItem = data; Console.log ('returned' + data);  

console.log ('returned' + data); Returns:

brought back [object object]

I'm not sure why this error may occur It seems that promise Console Should pass through data returned in logs;

This is a quote from Javascript string consonant if you have any type of log < / Code>, the console will show the entire object friendly, on which you will screenshots. However, if you have log a string and an object, then the JavaScript interpreter will dice the object as opposed to string correctly as [object object] . The object is hardly okay; The log statement is just giving you a type of version of it.

The easiest way is here:

  console.log ('brought back'); Console.log (data);  

or:

  console.log ('returned', data);  

Then your entire object will be logged separately with your visual hierarchy of the string and properties of your identity, you will avoid the string combination problem, and everything should look good.


No comments:

Post a Comment