Allow binding to getter/setter fn
Now, when we have "accessor" locals, one should be able to bind to accessor. So either $parse or ng-model shoul handle it.
This is ugly - with binding to getter/setter, I wouldn't have to do the extra "value" and copying back and forward: http://jsfiddle.net/vojtajina/XuhzP/64/
The tpl of the component would be just:
<span ng-hide="editMode" ng-click="editMode=true">{{model()}}</span>
<input type="text" ng-model="model" ng-show="editMode" ng-enter="editMode=false" />
Another ugly solution (taking advantage of obj reference from parent scope): http://jsfiddle.net/vojtajina/XuhzP/65/
+1
+1 Would be great for a data-store with many entries to detect which entries are dirty.
I believe the new directive scope syntax takes care of this. See "Directive Definition Object" here: http://docs.angularjs.org/guide/directive
Can I close this?
As far as I can tell, ng-model does not yet support getter/setters. And this is what the example above is about.
Tobias
Oops, I totally misunderstood. I get it now; thanks! I also think this would be a good feature.
So implementation-wise, we just check if ng-model is a function, and if so assume it's a getter/setter?
Yes, kind of this. However, don't know if ng-model is the best place for this....
Also ng-model doesn't watch for deep changes in the case that the model is an array.
On 24 July 2012 19:49, Tobias Bosch < [email protected]
wrote:
Yes, kind of this. However, don't know if ng-model is the best place for this....
Reply to this email directly or view it on GitHub: https://github.com/angular/angular.js/issues/768#issuecomment-7228348
+1
+1
+1
+1
+1
So things have changed since this ticket was opened (as ng-model-instant is no more), but couldn't we do something like:
ng-model="function()"
and ng-model would take that thing, call it when it needs to read, and call function(new_val) when things change.
Or it could pass as the first parameter, the $scope all the time.. (even in "getter" mode).. so that we have context. What do you think ?
what about allowing the user to assign an ng expression {{}} in ng-model that gets evaluated to an object for two way data-binding?
+1
+1
Really need this to write code that use third party librairies where model properties are getter/setter.
Edit: I made a workaround using ES5 get/set: http://plnkr.co/edit/c863Z267jdM7KygfBUi8
:+1:
:+1:
Just ran into another checkbox use case that really needs getter/setter support...