[英]How to create Child Controller Angular Js
define([], function() {
function myCtrl($scope,$http)
{
$scope.test = "Course Man";
}
myCtrl.$inject=['$scope','$http'];
return myCtrl;
});
We have separate file for each controller and lazy loaded when required.. They have corresponding entry in application.js. 我们为每个控制器都有单独的文件,并在需要时进行延迟加载。.它们在application.js中具有相应的条目。
Now the problem is : 现在的问题是:
I need 2-3 child controllers all linked to a parent controller.. and all are there in a single file.. so that they can be loaded.. 我需要2-3个都链接到父控制器的子控制器。并且都在一个文件中..以便可以加载它们。
Tried : 尝试过:
define([], function() {
function myCtrl($scope,$http)
{
$scope.test = "Course Man";
}
function myCtrl1($scope,$http){};
myCtrl.$inject=['$scope','$http'];
return myCtrl;
});
but, dosen't seems to be working. 但是,似乎没有用。
UPDATE ---- 更新----
Parent -- 父母-
define([], function() {
function myCtrl($scope,$http)
{
$scope.test = "Course Man";
}
myCtrl.$inject=['$scope','$http'];
return myCtrl;
});
With another controller : 与另一个控制器:
define([], function() {
function myCtrl($scope,$http)
{
$scope.test = "Course Man";
}
return myCtrl;
});
function myCtrl1($scope,$http){
};
This is working .. not sure they have parent child relationship or not... confused ! 这很有效..不确定他们是否有亲子关系...困惑!
You can go the other way. 您可以选择其他方式。
it is possible to extend a controller or make a single controller a mixin of multiple controllers. 可以扩展一个控制器或使一个控制器成为多个控制器的混合。
module.controller('CtrlChild', ['$scope', '$controller', function ($scope, $controller) {
// Initialize the super class and extend it.
angular.extend(this, $controller('CtrlParent', {$scope: $scope}));
… Additional extensions to create a mixin.
}]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.