angularjs - angular js content not wrapped inside the return resource object -
i have service class in angular calls backend , gets userinfo object. angular service class has following.
var userresource = $resource(coreurl+'getfullprofile', {}, { getuserinfo: { method: 'post' } userservice.getuserinfo = function (userobj) { var res = userresource.getuserinfo(); var promises = res.$promise; return promises; }
my controller class has following.
promise = userservice.getuserinfo(); promise.then(function (response) { $scope.user = response; });
my backends service returns object.
my problem user info object backend not wrapped inside object.the object mix angular variables. dont have response.data
.the response object has information.
$promise: objectcatch: function (callback) {finally: function (callback) {then: function (callback, errback, progressback) {__proto__: object $resolved: true about: "sdadsf" country: "india" creationdate: "2015-04-07" email: "user3" id: 3 industries: array[2] name: "user3" phoneno: 0 progresslevel: 1
the above response contains $promise , $resolved combined in object. how can data separately object.
controller.js
(function () { var usercontroller;
usercontroller = function ($scope, userservice, searchservice) { var delegate; var masteruser; $scope.user = {}; $scope.neweducation = []; $scope.newprofession = []; $scope.editmode=false; $scope.hospitals=[]; $scope.yearoptions={ 'year-format': "'yy'", 'starting-day': 1, 'datepicker-mode':"'year'", 'min-mode':"year" }; $scope.hospit=function(){ promise = userservice.gethospitals(); promise.then(function (response) { $scope.hospitals = response.data; }); }; delegate = { getuserinfo: function () { userservice.getuserinfo(this.ongetuserdata,this.ongeterror); }, ongetuserdata :function(data){ var usr = (new dcuser(data)); $scope.user = usr; $scope.masteruser = angular.copy(usr); }, ongeterror :function(data){ alert("error"); }, saveuserinfo:function(){ alert('saveuserinfo'); userservice.saveuserinfo($scope.user,this.onsaved); }, onsaved:function(){ $scope.editmode=false; }, enableedit:function(){ $scope.editmode = true; }, canceledit:function(){ angular.copy($scope.masteruser, $scope.user); $scope.editmode = false; delegate.getuserinfo(); }, getindustries :function(){ alert("getindustries"); }, searchhospitals :function(){ searchservice.searchhospitals("a",this.ongethospitals); }, ongethospitals :function(data){ $scope.hospitals = data; }, searchmedicalschools :function(){ searchservice.searchmedicalschools("a",this.ongetmedicalschools); }, ongetmedicalschools :function(data){ $scope.medicalschools = data; }, connectuser:function(user){ alert("connectuser"); userservice.connectuser(user,this.onconnectsuccess,this.ongeterror); }, onconnectsuccess:function(){ alert("connection request sent"); }, initprofiecompletion: function(){ alert("in"); $scope.user.profession = []; $scope.user.profession.push({ "hospital": "as", "speciality": "as", "fromdate": "", "todate": "" }); promise = userservice.gethospitals(); promise.then(function (response) { $scope.hospitals = response.data; }); }, addeducation:function(){ $scope.neweducation.push({ "medicalschool": "", "speciality": "", "degree": "", "graduatedyear": "" }); }, addprofession:function(){ $scope.newprofession.push({ "hospital": "", "speciality": "", "fromdate": "", "todate": "" }); } }; return $scope.delegate = delegate; } dc.usermodule.controller('usercontroller', usercontroller);
}).call(this);
service.js
(function () { "use strict"; dc.app.service('userservice', ['$rootscope','$resource', '$http', function ($rootscope,$resource, $http) { var userservice = {}; var coreurl = $rootscope.coreuri+'user/'; var userresource = $resource(coreurl+'getfullprofile', {}, { getuserinfo: { method: 'get' }, saveuserinfo: { method: 'post', url: coreurl+'updateuserinfo' } }); var connectresource = $resource(coreurl + 'connectrequest',{}, { connectuser: { method: 'post' } }); var userphotoresource = $resource(coreurl + 'uploadphoto', {}, { uploadphoto: { method: 'post' } }); userservice.getuserinfo = function (onsuccess,onfailure) { return(userresource.getuserinfo(onsuccess,onfailure)); }, userservice.saveuserinfo = function(user,onsuccess){ return userresource.saveuserinfo(user,onsuccess); }, userservice.connectuser = function(user,onsuccess,onfailure){ return connectresource.connectuser(user,onsuccess,onfailure); }, userservice.uploadphoto =function(image){ var promises = userphotoresource.uploadphoto(image); return promises; }, userservice.gethospitals = function(){ alert('ser'); var promises = $http.get('dcresources/hospitals.json'); return promises; } return userservice; }]); }).call(this);