I need to get an inserted object immediately after insertion has been done. But this is a problem with Angularjs $resource.
module.factory('SearchQueries', function($resource){
return $resource('/instances/searches/:_id', {_id: '@id'});
});
var new_search = new SearchQueries({query: query});
new_search.$save(function(new_query){
console.log(new_query);
console.log(new_query.id, new_query.query);
console.log(new_query.$get()); // This is undefined
$scope.searchQueries.push(new_query);
});
Server response:
{"query": "inserted text", "id": 53}
new_query
printed in a console:
h {query: "f7b1b2214bda4aa29b7ef5029c918590", id: 53, $get: function, $save: function, $query: function…}
$$hashKey: "01J"
id: 53
query: "inserted text"
new_query.id, new_query.query
printed in a console:
53 "f7b1b2214bda4aa29b7ef5029c918590"
Instead of inserted text I have some kind of hash. By the way, what the hash is this?
In the template a bit of millisecond a new_query
is a hash, after $get
is done (success) the new_query
is inserted text. How to get inserted text directly after $get
successed?