2
Description
I am implementing a $http request with angular. I want to return the database objects.
Code
Companyservice.coffee
angular.module('vaultfactor').factory 'CompanyService', ($http, $q) ->
getCompanies: ->
promise = $http.get "/companies"
company = promise.then((response)->
if typeof response.data == 'object'
console.log(response.data)
return response.data
else
return $q.reject(response.data)
(response)->
$q.reject(response.data))
main_ctrl.coffee
angular.module('vaultfactor').controller 'HomeCtrl', ($scope, $rootScope,
$location, $http, CompanyService) ->
console.log(CompanyService.getCompanies())
Problem
The returned object is not the model you expected.
Giving a console.log to my sponse.date. before Return it returns me exactly what I need. like this: ( Being passed in dependencies $q, I posted an older image. )
Console.log:
What I’m going through wrong in my Success’s Return?
I work perfectly!
– ralfting