Updating ngSrc doesn't work

1,928 views
Skip to first unread message

John B.

unread,
Mar 17, 2013, 9:13:54 PM3/17/13
to ang...@googlegroups.com
Hi all,

I am trying to update ng-src of an image from inside a controller, after receiving an event (after $compile). But it doesn't work.
The event is received, but the image source doesn't update.

Please see my Plunkr.

Any ideas why?

Regards
John

John B.

unread,
Mar 17, 2013, 9:49:10 PM3/17/13
to ang...@googlegroups.com
Turns out I need to use $scopy.$applyhttp://plnkr.co/edit/W08AfPjDrgJMpZMWwMaM?p=preview

Thanks a lot to user bc on IRC. I'm sure I would have wasted another hour ;) 

Pawel Kozlowski

unread,
Mar 18, 2013, 7:38:48 AM3/18/13
to ang...@googlegroups.com
Hi!

While your plunker works I would suggest to move scope.apply to the
sending end since in there you _know for sure_ that you are "outside
of AngularJS world" (DOM event handler):
http://plnkr.co/edit/adtGAiwkgxXRMBb691Fa?p=preview

Personally I wouldn't probably use events here and simply relay on
data binding here, but feel free to ignore this remark as I'm not 100%
sure what is the purpose of your directive :-)

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+u...@googlegroups.com.
> To post to this group, send email to ang...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Looking for bootstrap-based widget library for AngularJS?
http://angular-ui.github.com/bootstrap/

John B.

unread,
Mar 18, 2013, 12:17:07 PM3/18/13
to ang...@googlegroups.com
Thank you Pawel, that makes sense. I have changed my code accordingly.
The Plunker was a very simplification of my problem, in reality I would rely on data binding as well :)
Reply all
Reply to author
Forward
0 new messages