Angular repeat and directive scope issue

Showing 1-3 of 3 messages
Angular repeat and directive scope issue Adriaan Bouman 11/29/12 2:47 PM
I have a repeater which creates a bunch of directives. Each directive keeps track of it's own cloneState. When a directive's cloneState is false, and the directive hasn't been cloned, it can't be deleted. This works as long as I haven't deleted/removed a previous directive. So the problem is that all directives can be removed and scope.cloned is set to true for all instances when some other record is removed.

A fiddle can be found here: http://jsfiddle.net/adriaanb/PGBYE/

What I want to achieve is that te last/empty row can't be deleted. But, like i said, it's scope.cloned is modified when some other allready cloned row is removed.

I can't wrap my head around it...maybe I am doing something wrong?

Thanks in advanced!
Re: [AngularJS] Angular repeat and directive scope issue Pete Bacon Darwin 11/30/12 6:10 AM
Um, is it that you just don't want the user to end up with zero rows?

If so then can't you do this?

<a ng-hide="results.length=1" ng-click="...">Remove</a>


--
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-US.
 
 

Re: [AngularJS] Angular repeat and directive scope issue Adriaan Bouman 11/30/12 6:26 AM
Hi Peter,

Thanks for your response!

The Fiddle is more a proof of concept (discussed during a angular meetup), and not used within a project I am currently working on. From a UX p.o.v. the solution you mentioned would be perfect!

The strange issue I ran into is something I can't wrap my head around. Every row/directive has it's own scope (scope true in directive) with it's own variables (cloneState, cloned, etc). The last empty/row/directive can't be removed, so scope.cloned is false for the last row. This works as long as you don't remove some previous row. After removing a previous row the empty row's scope.cloned is set to true and the remove button will work. Looks like Angular does something that isn't clear to me...

I have a another look at it this weekend, maybe I am missing something or I forget to check something...

greetings,
Adriaan 



Op vrijdag 30 november 2012 15:10:42 UTC+1 schreef Peter Bacon Darwin het volgende: