动态创建已包含内容的指令时出错

时间:2019-02-10 16:14:06

标签: javascript angularjs angularjs-directive

在我的应用程序中,我动态地创建了一个指令,该指令包含要包含到容器(div)中的已包含内容。我将这种方法用于已经完成的几个组件,并且效果很好。但是现在我遇到了一个问题,因为该指令已包含了内容。我收到这样的错误:

  

angular.js:14199错误:[$ compile:ctreq]指令'compB'所需的控制器'compA'找不到!

任何帮助将不胜感激

这是创建组件并将其添加到容器的代码

var newScope = $rootScope.$new(true);
newScope.elementConfig = elementConfiguration;
newScope.componentApi = {};
containerElement.append($compile(elementToHost)(newScope));

这是我要添加到容器中的组件

<field
    type="{{type}}"
    model=""
    mdt="{{mdt_type}}"
    label="{{label}}"
    placeholder="{{placeholder}}"
    maxlength="{{maxlength}}"
    req="isMandatory"
    editable="editable"
    is-disabled="disabled">

<micro-help micro-help="{{'text.label' | translate }}"
                as-tooltip="true"
                position="right"
                micro-help-icon="fa-globe">
    <div>
        <micro-help-localization>
        </micro-help-localization>
    </div>
</micro-help>

</field>

1 个答案:

答案 0 :(得分:0)

当HTML编译器尝试处理在指令定义中指定require选项的指令,但是当前DOM元素(或其祖先元素,如果{{ 1}})。

要解决此错误,请确保必需的控制器名称中没有拼写错误,并且当前元素中存在必需的指令控制器。

有关更多信息,请参见AngularJS Error Reference - $compile:ctreq Missing Required Controller

相关问题