Accessing child scopes in ng-repeat

3,956 views
Skip to first unread message

tas pas

unread,
Feb 6, 2013, 2:10:02 PM2/6/13
to ang...@googlegroups.com
Hello all, 

I have a ng-repeat that displays some items in an array.
I each one of these I have a button that executes some function for each given item.
I want to change the button to some graphic whenever a item is being processed. 

I reckon that I have to access the child scope in order to change a variable corresponding to the view.
But I cannot access each individual scope created by the ng-repeat.
Is there a way to do this?

Thank you.


Pawel Kozlowski

unread,
Feb 6, 2013, 2:21:23 PM2/6/13
to ang...@googlegroups.com
Hi!

On Wed, Feb 6, 2013 at 8:10 PM, tas pas <tpro...@gmail.com> wrote:
> I reckon that I have to access the child scope in order to change a variable
> corresponding to the view.
> But I cannot access each individual scope created by the ng-repeat.

Well, within markup for the ng-repeat element you've got access to a
scope created by a repeater for each and every element.
You could even define a controller for each repeated element.

> Is there a way to do this?

I'm still not 100% clear what exactly didn't work for you. Could you
send a plunker with what you have tried?

Cheers,
Pawel


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

tas pas

unread,
Feb 6, 2013, 3:14:52 PM2/6/13
to ang...@googlegroups.com
Sure...
http://plnkr.co/edit/2NfeybajOskfmlHKKotD

Hope it makes sense

:)

Pawel Kozlowski

unread,
Feb 6, 2013, 3:23:42 PM2/6/13
to ang...@googlegroups.com
Hi!

Grr, still not very clear about the thing you are after. Sorry,
probably to tired today...
Sth like this? http://plnkr.co/edit/t3POkDnzAynClh6dcGSI?p=preview

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.

tas pas

unread,
Feb 6, 2013, 3:44:09 PM2/6/13
to ang...@googlegroups.com
Yes, something like this (thank you), but I want to display some loading indication
I could add to each array item a flag like this
but 
a) it doesn't work
b) it seems a little hacky to me.

Thanks :)

tas pas

unread,
Feb 6, 2013, 3:45:21 PM2/6/13
to ang...@googlegroups.com

Markus Zywitza

unread,
Feb 6, 2013, 3:49:35 PM2/6/13
to ang...@googlegroups.com


2013/2/6 tas pas <tpro...@gmail.com>

tas pas

unread,
Feb 6, 2013, 4:04:46 PM2/6/13
to ang...@googlegroups.com
Sweet!

So, you created a scope variable, which gets multiplied in each repeat/ child scope and then...

$scope.isSelected = function(person) {
    return $scope.state.selected === person;
  }

I don't seem to get it.
Can you please explain what is the scope of the $scope in the function above?

Thank you

tas pas

unread,
Feb 6, 2013, 4:34:04 PM2/6/13
to ang...@googlegroups.com
I got it, It seems that the $scope.state.selected is a parent variable and does not get multiplied in the iterations of the ng-repeat.
It just holds the item selected.

Thank you!
Reply all
Reply to author
Forward
0 new messages