javascript - How can I modify the properties of a promise to be equal to the properties of an object in AngularJS? -


basically, trying create generic function in service takes values of 1 object , checks see object if of parameters shared, , if are, replaces original object's parameter value of shared parameter in new object. function works json object , looks this:

load: function(loadtrue, settings1, settings2) {   if (loadtrue) {     (var prop in settings1) {       if (settings2.hasownproperty(prop)) {         settings1[prop] = settings2[prop];       }     }     return settings1;   }   else{     return settings1;   } }, 

like said, works fine json object, problem i'm facing when try compare resource object (the second item in function have plain json object due nature of project, can't returning object, resource returning).

here 2 objects comparing when log them in console:

figure 1

settings1: resource {$promise: object, $resolved: false} settings2: object {class: "messagetype", id: 181, message: "test messageee"…} 

however when expanded, 2 similar:

figure 2

settings1: $promise: object $resolved: true class: "messagetype" id: 181 message: "test" messagename: "testing 1"  settings2: class: "messagetype" id: 181 message: "test messageee" messagename: "testing 1" 

as can see, need overwrite message property in settings1 of settings2. problem seems (when going through debugger), instead of going through figure[2], angualr seems through figure[1] , sees there no shared parameters between 2 objects, , nothing on written.

the method call looks like:

$scope.subject = myservice.load($scope.loadistrue, $scope.subject, $localstorage.subject2); 

subject declared so:

$scope.subject = messageservice.messageresource.get({messagename: 'test'}); 

try these changes:

in messageservice service (you have change match method):

get: function (message) {             var deferred = $q.defer();              $http({                 url: '/yourhttpcall',                 method: "get",                 datatype: 'json'             }).success(function (data, status, headers, config) {                                     deferred.resolve(data);                                                                     }).error(function (data, status, headers, config) {              });             //this line key             return deferred.promise;         } 

then in other code making calls

messageservice.messageresource.get({messagename: 'test'}).then(function(data){    $scope.subject = data; }).then(function() {    myservice.load($scope.loadistrue, $scope.subject, $localstorage.subject2); }); 

Comments