Call a function in ng:model

11,123 views
Skip to first unread message

tradeshift...@gmail.com

unread,
Aug 20, 2012, 11:43:23 AM8/20/12
to ang...@googlegroups.com
hey Angulars,

can I call a function in ng:model instead of passing a string?

here is my code it seems I'm missing something!


Thanks and have a great day!
Nicco

Ricardo Bin

unread,
Aug 20, 2012, 3:03:05 PM8/20/12
to ang...@googlegroups.com, tradeshift...@gmail.com
Hey Nicco,

Sorry, but i didnt understand your point. Whats your fiddle suppose to work?

vinay...@gmail.com

unread,
Aug 20, 2012, 3:13:33 PM8/20/12
to ang...@googlegroups.com, tradeshift...@gmail.com
Yeah, you can use a function. In which case the ng-model will be the value returned by the function. 

If the returned value is an expression you will have to eval it yourself, I have changed your fiddle:

Doing an eval in markup:


Doing an eval in the Ctrl:


Vinay.

nic...@gmail.com

unread,
Aug 20, 2012, 3:15:40 PM8/20/12
to ang...@googlegroups.com
Thanks for the quick reply :)

Message has been deleted

nic...@gmail.com

unread,
Aug 20, 2012, 5:54:02 PM8/20/12
to ang...@googlegroups.com
Thats not a good news! So if setters don't work what can I do? Some workaround?

Pawel Kozlowski

unread,
Aug 20, 2012, 5:58:45 PM8/20/12
to ang...@googlegroups.com
hi!

On Mon, Aug 20, 2012 at 11:54 PM, <nic...@gmail.com> wrote:
> Thats not a good news! So if setters don't work what can I do? Some workaround?

Yeh, setters are not supported at the moment, there are couple of
issues already opened for this:

https://github.com/angular/angular.js/issues/768
https://github.com/angular/angular.js/issues/945

The only work-around I can think of is binding to a variable, watching
it (scope.$watch()) and invoking a setter in a watcher... didn't try
it in practice thought...

Cheers,
Pawel

tradeshift...@gmail.com

unread,
Aug 21, 2012, 3:49:39 AM8/21/12
to ang...@googlegroups.com
could it be a solution to create a directive that for every generic element does get the path using the function and insert it in the ng:model? if yes will I have to create a directive for every kind of input or can I make a generic one? if yes can you explain how?

Thanks
Niccolo

tradeshift...@gmail.com

unread,
Aug 22, 2012, 4:02:45 AM8/22/12
to ang...@googlegroups.com, tradeshift...@gmail.com
Looks like calling function in ng:model is not allowed at all in 1.0.1 :( not even for getters.
Reply all
Reply to author
Forward
0 new messages