Simple Table Row Selection Toggle

2,948 views
Skip to first unread message

Bruno Tourinho

unread,
Nov 7, 2012, 12:09:16 AM11/7/12
to ang...@googlegroups.com
Hello guys (and eventually girls), 

My name is Bruno, I'm a web developer from Brazil and Adobe Flex orphan.

I'm new in the group, and new in this Angular world...

I'm making some tests, trying to move from jQuery, but found some easy things jQuery did, it's really complicated in Angular, or maybe I'm not "there" yet...

What I'm trying to achieve, toggle selection to the table row on click, and mark it with .active (css), with the minimum code as possible, any ideas? 

thanks in advance...

my fiddle...



Максим Михайленко

unread,
Nov 7, 2012, 1:43:56 AM11/7/12
to ang...@googlegroups.com
Try this modification http://jsfiddle.net/JsUUP/5/

Bruno Tourinho

unread,
Nov 7, 2012, 6:35:33 AM11/7/12
to ang...@googlegroups.com
That's amazing Max! Worked like a charm!

Would you mind explaining, how did you make it work?

I can see you changed the ng-class="{true:'active',false:''}[active.id == pessoa.id]" and the toggle function

$scope.toggleItem function(pessoa{
        console.log(pessoa);
        $scope.active pessoa;
      };

concerning the ng-class I didnt'quite get the expression, you made the "active" var boolean like? how about the bracketed part [active.id == pessoa.id]?

anyway, thank you very much, I'm really excited learning new techniques from the pros...

regards




--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Ivo Reis

unread,
Nov 7, 2012, 11:54:03 AM11/7/12
to ang...@googlegroups.com
Bruno that expression means:

1. First creates an object myObject = {true: 'active', false: ''} 
2. Then you will call the key that you want, like myObject.true this will return 'active', this is the same as calling myObject[true] but with different notation. 

Bruno Tourinho

unread,
Nov 7, 2012, 12:09:34 PM11/7/12
to ang...@googlegroups.com
Nice, thank you Ivo... 
Think there's a long way until I can really build the things right... :)

Kai Groner

unread,
Nov 8, 2012, 8:53:21 AM11/8/12
to ang...@googlegroups.com
If you give ng-class on object it will select the keys that are truthy, so you can do ng-class="{active: active.id == pessoa.id}".
Reply all
Reply to author
Forward
0 new messages