Re: [angular.js] view not updating on $scope.modelName = someValue;

5,952 views
Skip to first unread message

Suller Andras

unread,
Jun 10, 2012, 12:52:24 AM6/10/12
to ang...@googlegroups.com
Hi,

Is looks like $scope.$apply solves the issue:
http://jsfiddle.net/GJJMT/13/

Andras

On Sun, Jun 10, 2012 at 10:47 AM, Joel Holdbrooks
<cjhold...@gmail.com> wrote:
> I've spent a bit of time trying to figure this one out, I'm hoping someone
> out there can help clue me in to whats missing.
>
> Here's the fiddle:
>
> http://jsfiddle.net/cjholdbrooks/GJJMT/9/
>
> Basically I have a directive (snippet), a service (tokenService), a
> controller (TokenCtrl), and some code which has been run through CodeRay (a
> syntax highlighter). Whenever someone clicks on one of the "tokens" in the
> code (ie. a span) I would like to see the name of the token displayed. I'm
> trying to figure out why the binding tokenName doesn't update in the view
> when it's changed. If you open the console, it shows everything is working
> fine.
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/LLLd9KYbGUYJ.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

Dan Doyon

unread,
Jun 10, 2012, 1:19:57 AM6/10/12
to ang...@googlegroups.com
I came up with a slightly different way but essentially the same


--dan



On Jun 9, 2012, at 10:08 PM, Joel Holdbrooks wrote:

Thanks so much! I really appreciate the help!
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/vig6azFWWzsJ.

Igor Minar

unread,
Jun 19, 2012, 4:17:07 PM6/19/12
to ang...@googlegroups.com
I looked at this and I actually think that you are not thinking about the solution correctly.

Forget events, in angular scope events should be used only in very special cases when data-binding is not suitable.

Instead, embrace data-binding whenever possible: http://jsfiddle.net/IgorMinar/zw6dw/8/

/i

On Sun, Jun 10, 2012 at 8:28 PM, Joel Holdbrooks <cjhold...@gmail.com> wrote:
Ah, very nice. I like this approach as well. There's so much packed in to angular, it's nice to have such a helpful community, thanks!
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/r46aA4jM1t4J.

Dan Doyon

unread,
Jun 19, 2012, 4:30:39 PM6/19/12
to ang...@googlegroups.com
nice!


From: Igor Minar <ig...@angularjs.org>
To: ang...@googlegroups.com
Sent: Tuesday, June 19, 2012 1:17 PM
Subject: Re: [angular.js] view not updating on $scope.modelName = someValue;

Vojta Jína

unread,
Jun 30, 2012, 8:38:22 PM6/30/12
to ang...@googlegroups.com
$$phase is either '$apply' or '$digest' or null

So yep, if (!scope.$$phase) scope.$apply() will work. Although, it's highly recommended to to not have code being executed sometimes within apply and sometimes outside.

V.


On Thu, Jun 21, 2012 at 10:10 PM, ItsLeeOwen <l...@coderebelbase.com> wrote:
Sorry typo, I believe you should only run a digest if $scope.$$phase is false. if( !$scope.$$phase ).  I'll double check later.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/PFqGqhiudccJ.
Reply all
Reply to author
Forward
0 new messages