angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Allow binding to getter/setter fn

Open vojtajina opened this issue 14 years ago • 47 comments

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/

vojtajina avatar Mar 05 '12 01:03 vojtajina

+1

hartym avatar Apr 04 '14 11:04 hartym

I'll work on this.

btford avatar Apr 07 '14 20:04 btford

+1

jeffbcross avatar Apr 07 '14 20:04 jeffbcross

Just to be clear this issue is about improving the way we databind to getter/setters implemented via jQuery style methods.

A good example of this api is $location.path which when called as $location.path() functions as a getter and when called as $location.path(newValue) functions as a setter.

The problem we have is that if we just considered all functions to be getters/setters by default we would lose access to function references. So for this reason we can't implement uniform access within the expression language.

One potential solution is to implement this only for ngModel:

<input ng-model="$location.path(newNgModelValue)">

or just:

<input ng-model="$location.path()">

IgorMinar avatar Apr 07 '14 20:04 IgorMinar

Might be worth noting that we represent invalid value as undefined in ngModel, which is the same as the getter style call for jquery getters - how can we disambiguate that?

On Montag, 7. April 2014 13:42:53, Igor Minar [email protected] wrote:

Just to be clear this issue is about improving the way we databind to getter/setters implemented via jQuery style methods.

A good example of this api is $location.path which when called as $location.path() functions as a getter and when called as $location.path(newValue) functions as a setter.

The problem we have is that we we just considered all functions to be getters/setters by default we would lose access to function references. So for this reason we can't implement uniform access within the expression language.

One potential solution is to implement this only for ngModel:

or just:

Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/768#issuecomment-39780740 .

mprobst avatar Apr 07 '14 22:04 mprobst

Closed via b9fcf017316d37e91959949f56692644ce09d54a.

btford avatar Jul 08 '14 10:07 btford

Sweet! That's great, thanks a lot :)

abourget avatar Jul 08 '14 13:07 abourget