In my application I have a model attached to a form which is something like that:
$scope.location = { description: "my descriptive description", address: "blah" }
Cleaning the field "description" in the form, which is bound to ng-model="location.description", removes the field from $scope.location which becomes:
$scope.location = { address: "blah" }
Now I would like it to retain the "description" field. What can I do in order to achieve this behaviour?
Thanks for your help
One possibility is using the ng-change directive:
<input ng-model="desc" ng-change="setDescription()">
And in your controller:
$scope.setDescription = function(){
$scope.location.description = $scope.desc ? $scope.desc: "default"
}
Building off of Kozlowski's comment: http://jsfiddle.net/myMyQ/2/