U
U
uoziod2013-11-21 16:27:04
JavaScript
uoziod, 2013-11-21 16:27:04

Angular: Access to neighboring scope or another way to manage "neighbors"

There is a problem, the answer to which I found on StackOverflow . There is a great tip to use sharing services. However, my task is a little more specific than the need to have access to "neighbors".
My case diagram:
- Scope 1 < controller
scope --- Scope 2 < 1st ngRepeat scope
--- Scope 3 < 2nd ngRepeat scope
--- Scope 4 < 3rd ngRepeat scope
--- Scope 5 < 4 th ngRepeat scope
Each ngRepeat has an INPUT with ngModel and ngChange referring to a function that validates the input's content. Each ngRepeat has its own input and each is validated. By default, all inputs starting from the second one are hidden, and should appear only if valid data was entered in the previous input.
And so I'm looking for the best and most accurate way to control the visibility of ngRepeat'ov...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Aleksei Podgaev, 2013-11-21
@alexiusp

Well, why does ng-Show not suit you?
Create an array of validity flags commensurate with the array used in ng-Repeat and give each element the ng-Show attribute. Something like this:

<div ng-repeat="item in items" ng-Show="isValid[$index]">
...
</div>

The validator function must set the appropriate flag to true when the next field can be shown.

A
Andrew, 2013-11-21
@OLS

And for unification, in addition to the previous answer by @alexiusp, I would suggest that the validation function be arranged uniformly in the same array, and call the validation process with a separate procedure with the $index parameter, which would call checkIfValid[i] and assign its result to the next element of the boolean array isValid[i+1].

M
mordamax, 2013-11-22
@mordamax

How do you wrap each ngRepeat element in an object?
those.
- Scope 1 < controller
scope --- Scope 2 < 1st scope ngRepeat object.profile
--- Scope 3 < 2nd scope ngRepeat object.contacts
--- Scope 4 < 3rd scope ngRepeat object.anythingelse
then in any of the scopes you refer to the previous one via object
being in ng-repeat="contact in object.contacts"
you use ng-if="!!object.profile.name"
Example on Plunker
Let me know if I understood the purpose correctly. Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question