Support universal access in angular expressions
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.
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.
you are forgetting about input/form widgets which need to be modified as well
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?
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?
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!
It would be nice to have this in angular.
A bit more discussion on the behaviour and I'm sure it will get PRs
Some support for this landed in b9fcf017316d37e91959949f56692644ce09d54a.