view not updating on $scope.modelName = someValue;

Showing 1-13 of 13 messages
view not updating on $scope.modelName = someValue; Joel Holdbrooks 6/9/12 8:47 PM
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.

Re: [angular.js] view not updating on $scope.modelName = someValue; Suller Andras 6/9/12 9:52 PM
Hi,

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

Andras
> --
> 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.
Re: [angular.js] view not updating on $scope.modelName = someValue; Joel Holdbrooks 6/9/12 10:08 PM
Thanks so much! I really appreciate the help!
Re: [angular.js] view not updating on $scope.modelName = someValue; Dan Doyon 6/9/12 10:19 PM
I came up with a slightly different way but essentially the same


--dan



To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/vig6azFWWzsJ.

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.

Re: [angular.js] view not updating on $scope.modelName = someValue; Joel Holdbrooks 6/10/12 8:28 PM
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!
Re: [angular.js] view not updating on $scope.modelName = someValue; Igor Minar 6/19/12 1:17 PM
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

To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/r46aA4jM1t4J.

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.

Re: [angular.js] view not updating on $scope.modelName = someValue; Dan Doyon 6/19/12 1:30 PM
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;
Re: [angular.js] view not updating on $scope.modelName = someValue; Joel Holdbrooks 6/21/12 4:33 PM
Thank you. Yet again I have learned something new. My issue may be a bit deeper, however.

I'm attempting to develop an application which allows for the generation of syntax highlighting schemes, see screenshot below:

I need to be able to communicate changes in the token properties between the editor on the right and the "buffer" on the left. The idea being, a user clicks on a "token" (ie. a keyword) in the "buffer", the form updates the inputs. At that point a user can choose new colors and font options, which in turn are reflected in the "buffer".

Currently, I am using a service to mediate this behavior and an object to keep track of the styling, but I am not sure if this the right approach now.

Can you share some insight?

Re: view not updating on $scope.modelName = someValue; Andrew Joslin 6/21/12 5:30 PM
I think the service is definitely your best approach. A shared model holding the state of the app between the buffer and the text.
Re: view not updating on $scope.modelName = someValue; ItsLeeOwen 6/21/12 6:15 PM
Careful with $apply and $digest.  If you have a lot of areas of an app using it, you might run into digest collision errors.  Someone mentioned checking $$phase before calling $digest.

if( $scope.$$phase )
     $scope.$digest();

Also, if you can use $digest, use that because it only reevaluates the current scope downwards, whereas $apply reevaluates everything from rootScope down.

Re: view not updating on $scope.modelName = someValue; Joel Holdbrooks 6/21/12 6:46 PM
Yeah, I did run in to those errors and ended up having to create separate broadcasts for handling color changes and font changes. This absolutely did not feel right because really they're one in the same (attribute, value) and it creates two paths in the code.

Are there any drawbacks to using the $scope.$$phase check like you're suggesting?

By the way thanks for explaining the difference between $digest and $apply. I haven't had the chance to completely read up on those.
Re: view not updating on $scope.modelName = someValue; ItsLeeOwen 6/21/12 10:10 PM
Sorry typo, I believe you should only run a digest if $scope.$$phase is false. if( !$scope.$$phase ).  I'll double check later.
Re: [angular.js] Re: view not updating on $scope.modelName = someValue; Vojta Jína 6/30/12 5:38 PM
$$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.

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.