我有观点
<section ng-controller="ParentController">
<!-- some contents -->
<my-directive controller="ChildController"></my-directive>
</section>
脚本
var app = angular.module('section', []);
app.controller('ParentController', ['$scope', function($scope){
//
}]);
app.controller('ChildController', ['$scope', function($scope){
//
}]);
app.directive('myDirective', function(){
return {
template : function(ele, args){
return '<section ng-controller="+args.controller+" ></section>';
},
restrict : 'E'
}
});
渲染完成后,'ChildController'不是函数,未定义'
为什么会这样?
答案 0 :(得分:0)
尝试这样做:
var app = angular.module('app', []);
app.controller('ParentController', ['$scope', function($scope){
//
}]);
app.controller('ChildController', ['$scope', function($scope){
//
}]);
&#13;