【问题标题】:Angular directive - asking for transclusion?角度指令 - 要求嵌入?
【发布时间】:2015-02-11 21:51:47
【问题描述】:

我在下面收到一个错误,我不明白为什么。有什么想法吗?

html,

<button ng-click="loadForm()">Load Directive Form</button>
<div data-my-form></div>

角度,

   app.directive('myForm', function() {
        return {
          replace:true,
          controller:function($scope){
            $scope.isLoaded = false;
            $scope.loadForm = function(){
              $scope.isLoaded = true;
            }
          },
          template: '<div ng-if="isLoaded" ng-include="\'form.php\'" ></div>',
          link:function(scope, element) {

          }
        }
    });

错误,

Error: [$compile:multidir] Multiple directives [ngInclude, ngInclude] asking for transclusion on: <div data-my-form="" ng-if="isLoaded" ng-include="'form.php'">

修复,

'<div><div ng-if="isLoaded" ng-include="\'form.php\'" ></div></div>'

但为什么我必须将它包装在一个 div 中?是角虫吗?

【问题讨论】:

  • 替换已弃用

标签: javascript php html angularjs angular-directive


【解决方案1】:

错误很明显。在尝试使用嵌入的同一元素上有两个指令:

1. ng-if 
2. ng-include

一个元素只能应用一个嵌入。

要修复,请尝试以下方法:

<div data-my-form="" ng-if="isLoaded">
   <div ng-include="'form.php'"> </div>
</div>

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2015-10-27
    • 1970-01-01
    • 2015-08-01
    • 2015-07-07
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    相关资源
    最近更新 更多