Angular: Compile is not defined

Angular: Compile is not defined

本文关键字:not defined is Compile Angular      更新时间:2024-02-22

我已经面临一个问题很长时间了。你能帮我解决这个问题吗。实际上,我想在很多地方使用table指令。所以我创建了一个指令,并将angular UI网格绑定到其中。但我遇到了编译错误。

错误:angular.min.js:102 ReferenceError:编译未定义

但我可以加载网格内容

我在这里做错了什么?

HTML
<div ng-controller="ctrl1 as two">
    <ltcg-table><ltcg-table>    
</div>
<div ng-controller="ctrl2 as two">
    <ltcg-table><ltcg-table>    
</div>
JS
myApp.directive('ltcgTable', function($compile) {
            return {
                restrict: 'E',
                transclude: true,       
                replace: false,                            
                scope: {  },
                controller: Controller,
                controllerAs: 'Controller',
                bindToController: true,            
                compile: compile   
            }
        });

compile函数(compile: compile的第二部分)未定义。它应该是以下形式的函数:

function compile(tElement, tAttrs, transclude) { ... }

所以,试着这样定义指令:

myApp.directive('ltcgTable', function($compile) {
    return {
        restrict: 'E',
        transclude: true,       
        replace: false,                            
        scope: {  },
        controller: Controller,
        controllerAs: 'Controller',
        bindToController: true,            
        compile: function(tElement, tAttr, transclude) {
            //do some stuff here
        }   
    }
});

或者,如果您不需要做任何特殊的事情,并且网格按原样工作,只需将compile字段排除在方向规范之外。