Scopes, ng-repeat and directives

A bit new to Angular and trying to deal with scopes. I understand that each pass through the collection via ng-repeat gets its own scope. What I don't understand is in the following code:

<tr data-ng-repeat="oneField in $parent.formEventDefinition">
  <ng-include src="getUrl(oneField.fieldType)"></ng-include>
  {{oneField.fieldType}}

      

In ng-include, oneField.fieldType is undefined

, but the {{}} directive on the next line writes the correct value to the page. Why does it find the correct out of scope value in one case but not in another?

Any answer or pointer to where the answer can be found is good. I try to learn and get lost.

Thank!

+3


source to share


2 answers


Since ng-include

creates subsidiary region of the current the current scope like ng-repeat

, ng-if

, ng-switch-when

, use $parent.oneField.fieldType

there



See this answer for more information

+1


source


It turns out this is not a scale issue. It turns out that the problem was that <tr>

it was not practical to embed the element in the element <ng-include>

, and Angular somehow enforces it. When I reworked the HTML to fit <ng-include>

inside <td>

, it all started magically.

Thanks for the help.



Dave

0


source







All Articles