Some Scope Problem while recursion

34 views
Skip to first unread message

Michael Welt

unread,
Oct 29, 2010, 1:09:50 PM10/29/10
to Angular
Hi,

i want to go through a structure in some kind of recursion, but the gui is not
acting the way i'd like it to :)

i attached the files for reproducing.

Short introduction to the main Model:

This is extracted from a "realworld" - Example so it maybe needs some explanation
on why i am doing things the way i did.

An array of products, each product has an array of attributes, and each attribute
can have attributes it self. This is where recursion takes place. Each product has
also a value called splitIdx which is a 2dimensional array. I need that for showing
purposes and sorting the attributes of the product. 
This splitIdx is where the code got broke, when i switch the products.
The splitIdx should tell the gui: show these attributes of product here, and these there.

thats why the code goes this way : 

<div ng:repeat="idxPart in currentProduct.splitIdx"> <!-- in real application it is just show left or right -->
  <div ng:repeat="idx in idxPart"> <!-- take all the idx which should be showed here -->
    <div ng:init="attribut = currentProduct.attributes[idx]"> <!-- tell the recursion on which attribut of the product to start -->
      <ng:include src=" 'recursion.html' ">
      </ng:include>
    </div>
  </div>
</div>

maybe this is just poor by my model design. or, as i guessed i just messed up with scope (sadly again).
anyway the product and it's attributes with subattributes are not correctly displayed. 
what did i mess up?

-- Michael

testrecursion.html
recursion.html

Misko Hevery

unread,
Oct 29, 2010, 1:58:25 PM10/29/10
to ang...@googlegroups.com
Hi Michael,

I took a look at your example and you got it mostly right. I am not sure what issues you were running into but:
  1. I think you want ng:eval not ng:init
  2. I have added some CSS to visualize it better
  3. The example does not from file:// on some browser like chrome since they consider loading the recursion.html as security violation. But it does work in safari. It should work on all browser from http://
Let me know if this solves the issue, or if there are some more things you head in mind.

-- Misko

--
You received this message because you are subscribed to the Google Groups "Angular" group.
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.

somescopeproblemwhilerecursion.zip

Michael Welt

unread,
Nov 1, 2010, 4:47:09 PM11/1/10
to ang...@googlegroups.com
Hi Misko, thank you so very much :)

it was mainly about my fault using ng:init instead of ng:eval ... i was aware of the file:// issue, i forgot to mention
that i run the example on local webserver.

thanks, and although i ran into some beginner failure :) the time it took me to challenge some more complex
model then this in angular is nothing in contrast then it took me in some "old fashioned way" ...

-- Michael 

Misko Hevery

unread,
Nov 1, 2010, 6:26:43 PM11/1/10
to ang...@googlegroups.com
glad you find angular useful, no tell all your friends. :-)
Reply all
Reply to author
Forward
0 new messages