Javascript 在指令控制器中使用编译时在模板中非法使用ngTransclude指令

Javascript 在指令控制器中使用编译时在模板中非法使用ngTransclude指令,javascript,angularjs,Javascript,Angularjs,我在我的指令控制器中使用compile来获取第一个指令元素并编译它,然后将其用于其他目的我不想使用我的指令的链接方法,是否有任何方法来消除此错误 我在这里转载了这个问题: HTML: <div data-ng-app="app"> <panel1> <panel> <input type="text" ng-model="firstName" />{{firstName}} <

我在我的指令控制器中使用compile来获取第一个指令元素并编译它,然后将其用于其他目的我不想使用我的指令的链接方法,是否有任何方法来消除此错误

我在这里转载了这个问题:

HTML:

<div  data-ng-app="app">
    <panel1>
        <panel>
            <input type="text" ng-model="firstName" />{{firstName}}
        </panel>
        <input type="text" ng-model="lastname" />
    </panel
在控制器中编译之前,从元素中删除ng TRANCLUDE属性

    app.directive('panel', function ($compile) {
        return {
            restrict: "E",
            replace: true,
            transclude: true,
            template: "<div><h1>handrouss</h1><div ng-transclude ></div></div>",
            controller: function($scope, $element) {
              var div = $element.find('div');
              //REMOVE ng-transclude attribute
              div.removeAttr('ng-transclude');
              var el = $compile(div[0])($scope);
              $scope.handrouss = el.html();
            },
            link: function (scope, elem, attrs) {
            }
        }
    });
由于转换已在指令的编译阶段完成,因此在控制器中编译时不再需要ng TRANCLUDE指令

    app.directive('panel', function ($compile) {
        return {
            restrict: "E",
            replace: true,
            transclude: true,
            template: "<div><h1>handrouss</h1><div ng-transclude ></div></div>",
            controller: function($scope, $element) {
              var div = $element.find('div');
              //REMOVE ng-transclude attribute
              div.removeAttr('ng-transclude');
              var el = $compile(div[0])($scope);
              $scope.handrouss = el.html();
            },
            link: function (scope, elem, attrs) {
            }
        }
    });

你真棒