Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 作用域、ng repeat和指令_Angularjs_Angularjs Directive_Angularjs Ng Repeat - Fatal编程技术网

Angularjs 作用域、ng repeat和指令

Angularjs 作用域、ng repeat和指令,angularjs,angularjs-directive,angularjs-ng-repeat,Angularjs,Angularjs Directive,Angularjs Ng Repeat,有些新的角度和试图来掌握范围。我知道通过ng repeat通过集合的每个过程都有自己的作用域。我不明白的是以下代码: <tr data-ng-repeat="oneField in $parent.formEventDefinition"> <ng-include src="getUrl(oneField.fieldType)"></ng-include> {{oneField.fieldType}} {{oneField.fieldType}

有些新的角度和试图来掌握范围。我知道通过ng repeat通过集合的每个过程都有自己的作用域。我不明白的是以下代码:

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

{{oneField.fieldType}
在ng include中,oneField.fieldType是
未定义的
,但下一行的{{}指令将正确的值写入页面。为什么它在一种情况下从范围中找到正确的值,而在另一种情况下却找不到

无论是一个答案还是一个指向我自己找到答案的地方的指针都是好的。我在努力学习,却迷路了


谢谢

因为
ng include
确实从当前运行的作用域创建了一个子作用域,就像
ng repeat
ng if
ng switch当
这样做时,use应该在那里使用
$parent.oneField.fieldType


更多信息,这不是范围问题。问题是在
元素中嵌套
元素是不合法的,Angular以某种方式强制执行这一点。当我重新编写HTML,将
放在
中时,它开始神奇地工作

谢谢你的帮助


Dave

ng include
{{}
表达式在同一范围内(
ng repeat
的迭代范围),它们应该都很好。你能用小提琴再现吗?这应该很好,在这里也适用: