2017-03-23 53 views
0

找不到指令「appContent」所需的控制器'appLeft'!Angular指令 - 未找到控制器指令

//app-nav(left) 
    app.directive('appLeft', function() 
    { 
     return { 
      restrict: 'E', 
      replace: false, 
      scope: { 
       leftItem: "=leftItem" 
      }, 
      controller:function($scope){ 
       this.title = $scope.leftItem; 
      }, 
      templateUrl: 'res/tpl/app-left.html', 
      link: function (scope, ele, attr) 
      { 
       scope.toggle=function(index){ 
        scope.leftItem[index].isShow = !scope.leftItem[index].isShow; 
       } 
      } 
     } 
    }); 
    //app-content 
    app.directive('appContent',function(){ 
     return { 
      require:'^appLeft', 
      restrict: 'E', 
      replace:false, 
      transclude:true, 
      scope:{}, 
      templateUrl:'res/tpl/app-content.html', 
      link:function(scope,ele,attr,appLeftCtrl){ 
       console.log(appLeftCtrl.title) 
      } 
     } 
    }); 

無法找到指令'appContent'所需的控制器'appLeft'!

+0

您可以加入你的HTML代碼?你如何在HTML上放置/使用指令? –

回答

0

請確保您的所需指令不在html DOM中的子指令之外,因爲appLef指令是父指令。

<app-left> 
    <app-content></app-content> 
</app-left> 

根據文件

當指令使用要求,除非指定控制器發現$編譯就會報錯。 ^前綴表示該指令在其父母上搜索控制器(不帶^前綴,該指令僅在其自己的元素上查找控制器)。

Demo