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

Support universal access in angular expressions

Open IgorMinar opened this issue 15 years ago • 7 comments

It would be nice if we supported universal access to property/methods just like scala. So I could do this:

function Controller() {
  this.foo = '23';
  this.bar = function() { return '23' };
}
// html template
<p>{{foo}} and {{bar}}</p>

note that I didn't have to do bar(), instead I simply bound to bar. It makes no sense to provide access to function reference in angular expressions.

similarly, if we try to assign stuff to bar e.g. {{bar = '24'}}, angular should invoke bar as bar('24'). The same applies to binding bar to input widgets, e.g. <input name="bar"> will call bar and expect it to be jquery style getter/setter.

IgorMinar avatar Jun 21 '11 18:06 IgorMinar

This is pretty straight forward. You need to change the ng:bind and ng:bind-template and ng:bind-attr behavior and it should work.

mhevery avatar Jun 22 '11 22:06 mhevery

you are forgetting about input/form widgets which need to be modified as well

IgorMinar avatar Jun 23 '11 14:06 IgorMinar

I'd be interested in working on this, as in my application my model layer would be much easier to build out if it had getters and setters rather than being limited to a POJO.

Seeing that this is issue is two years old though, is it still wanted/likely to be merged in if I can figure it out?

latentflip avatar Jan 30 '13 12:01 latentflip

It would be really useful. I already got myself calling methods as getters/setters plenty of times. But what if the user need to override the function with another function/value? Would it be assumed as a limitation leaving this as original method creator's responsibility?

Let's say:

function Controller() {
  this.foo = '23';
  this.bar = function() { return '23' };
  this.qux = this.foo;
}
// html template
<p>{{qux}}</p>

{{qux = bar}} would invoke `qux(bar)´, right? Not sure if this is a problem. Just thought.

Also, would it recursively resolve the result until a non-function is returned or just the named property would be evaluated?

caiotoon avatar Feb 22 '13 18:02 caiotoon

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

btford avatar Aug 24 '13 00:08 btford

It would be nice to have this in angular.

A bit more discussion on the behaviour and I'm sure it will get PRs

rodyhaddad avatar Sep 06 '13 19:09 rodyhaddad

Some support for this landed in b9fcf017316d37e91959949f56692644ce09d54a.

btford avatar Jul 08 '14 11:07 btford