0

我正在创建一个自定义指令,如下所示:

<directive-a attribute-a="customData" attribute-b="customKey">
   <!--Transcluded Content-->
</directive-a>

场景如下:

  1. 是在 a的directive-a范围内controllerA
  2. 该指令从customData(对象数组)接收customData(对象数组)controllerA并根据提供的特定键(customKey)对customData中的数据进行分组
  3. 它使用 transcludeFunction 插入一个ng-repeat动态使用的 javascript 并在其中嵌入 Transcluded-Content ng-repeat,然后最终编译其父级ng-repeat以显示列表。

Transcluded-Content 将充当模板(由用户传递),其中数据将由directive-a.

面临的问题是,当 Transcluded-Content 是静态的时,它可以正常工作,但是当 Transcluded-Content 是自定义用户创建的指令时,角度会报告以下错误

无法读取未定义的属性“X”。

这个错误的原因(我认为)是 Angular 在中查找用户传递的自定义指令的数据scope of controllerA并且无法找到它从而导致错误。

我该如何解决我的问题?

角度版本:1.5.8

JSFiddle 代码段

4

0 回答 0