ng-switch Problem

938 views
Skip to first unread message

Joshua Marsh

unread,
May 27, 2012, 12:44:27 AM5/27/12
to ang...@googlegroups.com
I have a little top piece of a page i'm working on that is separated from the rest of the main program. The point of the section is to display different things based on the state of a value in the controller. I've found that ng-switch seems to bugger with my ng-models, but ng-show/ng-hide does not. Is this by design or is there a bug.

Here are the fiddles:

http://jsfiddle.net/tAEMp/10/ - This is with ng-switch. If you enter a value in the form and click the Update button, I get 'undefined' in the console.

http://jsfiddle.net/tAEMp/9/ - This is with ng-show/ng-hide. In this case, I get the value that I enter in the field in the log.

While the fiddle only shows 2 states, I'd like to have 4-5 states, so ng-switch seems more reasonable. It seems like the alternate would be to have several scope variables and a bunch of ng-shows related to them (messy imho).

Andy Joslin

unread,
May 27, 2012, 5:44:22 PM5/27/12
to ang...@googlegroups.com
ng-switch will add/remove from the DOM the contents inside when appropriate.  ng-switch also creates a new scope.

http://jsfiddle.net/tAEMp/11/ - This is using "$parent.name" instead of "name" - "name" would reference ngSwitchScope.name.

Renan T. Fernandes

unread,
May 27, 2012, 6:09:20 PM5/27/12
to ang...@googlegroups.com
ever use objects intead of string/numbers when you need to update the content from a child scope. The child scope wil have the reference of the object copied and you can update the values in the original object. http://jsfiddle.net/ShadowBelmolve/tAEMp/12/

2012/5/27 Andy Joslin <andyt...@gmail.com>
ng-switch will add/remove from the DOM the contents inside when appropriate.  ng-switch also creates a new scope.

http://jsfiddle.net/tAEMp/11/ - This is using "$parent.name" instead of "name" - "name" would reference ngSwitchScope.name.

--
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/-/1Ghff6lD0PkJ.

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.



--
Renan Fernandes(aka "ShadowBelmolve")

Joshua Marsh

unread,
May 28, 2012, 11:29:23 AM5/28/12
to ang...@googlegroups.com
Thanks guys! The $parent scope solved the problem. I guess this is just a different between switch and show/hide. Good to know.

For future reference, simply using an object didn't work for me. If I use the $parent scope, then the object example works: http://jsfiddle.net/icub3d/tAEMp/14/.


On Sunday, May 27, 2012 4:09:20 PM UTC-6, Renan T. Fernandes wrote:
ever use objects intead of string/numbers when you need to update the content from a child scope. The child scope wil have the reference of the object copied and you can update the values in the original object. http://jsfiddle.net/ShadowBelmolve/tAEMp/12/

2012/5/27 Andy Joslin
ng-switch will add/remove from the DOM the contents inside when appropriate.  ng-switch also creates a new scope.

http://jsfiddle.net/tAEMp/11/ - This is using "$parent.name" instead of "name" - "name" would reference ngSwitchScope.name.

--
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/-/1Ghff6lD0PkJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/angular?hl=en.
Reply all
Reply to author
Forward
0 new messages