Angularjs 角度指令-找不到控制器指令
找不到指令“appContent”所需的控制器“appLeft”Angularjs 角度指令-找不到控制器指令,angularjs,Angularjs,找不到指令“appContent”所需的控制器“appLeft” //app-nav(left) app.directive('appLeft', function () { return { restrict: 'E', replace: false, scope: { leftItem: "=leftItem" },
//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” 确保所需的指令在html DOM中的子指令之外,因为
appLef
指令是父指令
//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)
}
}
});
<app-left>
<app-content></app-content>
</app-left>
您可以添加html代码吗?您如何在HTML上放置/使用这些指令?