My problem was with the validation. If the value causes a form control 
validation, the ng-model is not set

On Wednesday, January 14, 2015 at 8:41:18 PM UTC+8, JP wrote:
>
> I'm using the $resource service to access and update resource to my API.
>
> However, I am having a problem when the value of an object attribute that 
> is bound to an ng-model is set to empty. The bound attribute gets deleted 
> from the object. Thus, when saving my resource the attribute is not anymore 
> present in the passed data.
>
> angular.module('myApp', [])
> .controller('myCtrl', function($scope, $resource) {
>    var Person = $resource('persons/:id.json', {id: @id});
>
>    $scope.data = Person.get({id:123});});
>
> Example resource response:
>
> {
>    id: 123,
>    name: 'Mike'}
>
> data.name is set to '' in the template below:
>
> <div ng-controller="myCtrl">
>    <input type="text" ng-model="data.name" />
>
>    <input type="button" ng-click="data.$save()" value="Save" /></div>
>
> data submitted via POST (name property is lost)
>
> {
>    id: 123}
>
> I need the element present on the passed data when saving because it will 
> determine if the API will set the actual value of the attribute to empty. 
> Otherwise, the attribute doesn't get updated and it retains its old value.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to