繁体   English   中英

在angularjs中嵌套视图,每个视图都有单独的控制器

[英]nested views in angularjs with each having separate controllers

我有一个观点

<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'不是一个函数,未定义'

为什么会这样?

尝试这样做:

 var app = angular.module('app', []); app.controller('ParentController', ['$scope', function($scope){ // }]); app.controller('ChildController', ['$scope', function($scope){ // }]); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM