【问题标题】:Getting AngularJS multilink error after upgrade from v. 1.4从 v.1.4 升级后出现 AngularJS 多链接错误
【发布时间】:2019-05-28 21:46:39
【问题描述】:

我有一个大指令,其中包含我收到错误的子指令。正是在main指令的link函数中调用transcludeFn()的步骤:

var link = function ($scope, elem, attr, parentCtrl, transcludeFn) {
            // Run all nested directives in order to properly register columns in grid.
            transcludeFn();

            // Add compiled content to directive element.
            elem.after($compile(template)($scope));
        };

无法解决这个问题。我在文档中错过了什么?将 $onInit 添加为 described here 并没有帮助(我不确定我这样做是否正确)。

我不熟悉 AngularJS,所以任何帮助都会是一个好点。

【问题讨论】:

    标签: angularjs angularjs-directive angularjs-compile


    【解决方案1】:

    我真的不知道问题的根源是什么,但我已经通过将一个虚拟函数传递给transcludeFn() 来解决它:

    var link = function ($scope, elem, attr, parentCtrl, transcludeFn) {
        // Run all nested directives in order to properly register columns in grid.
        transcludeFn();
        transcludeFn(function() {
            // do nothing, only for fixing upgrade issue 
        });
    
        // Add compiled content to directive element.
        elem.after($compile(template)($scope));
    };
    

    【讨论】:

    • +1 您的解决方案在将 AngularJS 1.5 升级到 1.6 时修复了此错误:“错误:[$compile:multilink] 此元素已被链接。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 2013-11-07
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多