ngResource $save is wiping out models
Date : March 29 2020, 07:55 AM
wish helps you Check your server side, I think you don't have description field in your server side model. So what happend? $scope.myModel is passed to server and updated by response object, response object does not contain description field
|
Unit-testing ngResource $save
Date : March 29 2020, 07:55 AM
To fix this issue If you use Jasmine's spyOn() function to verify that a $resource method is called, it overwrites the original $resource method with one that implements the "spying" functionality. If the code in your application relies on the $resource setting the $promise property, or it relies on the returned object/array from the $resource, the Jasmine's spy function won't return anything or set a value on the $promise property. As a result, perfectly fine code in your application will fail when being tested. A similar thing happens when you use $http with the then(), success(), or error() functions. // Newer Jasmine 2.0 syntax:
spyOn(resource, "$save").and.callThrough();
// Older syntax:
spyOn(resource, "$save").andCallThrough();
|
ngResource save() strange behaviour
Date : March 29 2020, 07:55 AM
This might help you Can someone please shed some light on this? , Try something like this Module.factory("Discount", ["$resource", function ($resource) { return $resource(GLOBALS.apiPath + "discounts/:Id", { Id: "@Id" }, {
somthingCustomIfNeeded: { method: 'POST', url: GLOBALS.apiPath + "something-custom" }
}); }]);
|
Angular ngResource's $save() not working
Date : March 29 2020, 07:55 AM
I wish this helpful for you I want to post data to my asp.net webapi controller, by using $save() method that belong to ngResource i am getting this error: "TypeError: $scope.product.$save is not a function at n.$scope.saveProduct " , Try this: $scope.product = productResource.get({ id: $scope.num });
$scope.saveProduct = function () {
$scope.product.$save(function (response) {...});
}
|
Using service, ngResource save
Date : March 29 2020, 07:55 AM
Hope this helps I'm new to Angular. , When you request add two callback functions as below: LanguagesService.save({
code: adminLang.newCode,
name: adminLang.newName
}, function(response){
// success
}, function(error){
// error
});
|