Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angularJs中,如何将控制器注入到另一个中_Angularjs - Fatal编程技术网

在angularJs中,如何将控制器注入到另一个中

在angularJs中,如何将控制器注入到另一个中,angularjs,Angularjs,我的问题是如何将控制器注入到另一个控制器中 这是我的第一个控制器: define([ 'module', '{angular}/angular' ], function(module, angular) { 'use strict'; var listAnimcom = angular.module('listAnimcom', []); listAnimcom.controller('listAnimcomCtrl', [ '$scope', function($scop

我的问题是如何将控制器注入到另一个控制器中

这是我的第一个控制器:

define([ 'module', '{angular}/angular' ], function(module, angular) {
'use strict';

var listAnimcom = angular.module('listAnimcom', []);

listAnimcom.controller('listAnimcomCtrl', [ '$scope', 
        function($scope) {
        $scope.testAnimcom="this controller is called";           
        } ]);

return {
         angularModules : [ 'listAnimcom' ]
       };
});
这是我的第二个控制器,我想在其中注入第一个控制器:

define([ 'module', '{angular}/angular',
     '{animcom}/modules/controllers/listAnimcom',
      ], function(module, angular) {
'use strict';

var plateformeDeTest = angular.module('plateformeDeTest', ['listAnimcom']);

plateformeDeTest.controller('plateformeDeTestCtrl', [ '$scope','listAnimcomCtrl',
        function($scope,listAnimcomCtrl) {
   $scope.typeActivite="polcom";
   $scope.typeClient="plateforme";

        } ]);

return {
        angularModules : [ 'plateformeDeTest' ]
       };
});
但它给了我一个错误:

 angular.js:12798 Error: [$injector:unpr] http://errors.angularjs.org/1.4.12/$injector/unpr?p0=listAnimcomCtrlProvider%20%3C-%20listAnimcomCtr... 
  at angular.js:38 
任何想法请

不能将一个控制器注入另一个控制器

为了在控制器之间共享数据,考虑使用工厂/服务。 最好通过这个答案来更好地理解

以工厂为例

var app=angular.moduleclientApp,[] app.controllerTestCtrl, 函数$scope,名称{ $scope.names=[]; $scope.save=函数{ 名称。添加$scope.name; } }; app.controllerTestCtrl2, 函数$scope,名称{ $scope.getnames=函数{ $scope.names=names.get; } }; 应用程序。工厂“名称”,函数{ 变量名称={}; names.list=[]; names.add=functionmessage{ names.list.push{message}; }; name.get=函数{ 返回name.list; }; 返回姓名; }; 拯救 {{name}}
可能重复关于StackOverflow上的控制器之间的通信有很多问题,请使用搜索,google也会在询问之前找到这些问题。请问您有具体的例子吗???@elogriamine查看演示,它显示了如何使用Factory在两个控制器之间共享数据谢谢,它解决了与我发布的示例有关的问题,但实际上,在我工作的示例中,第一个控制器变量function中有一个完整的业务逻辑。。我想在第二个控制器中重用这些元素,你可以说是以factorN的形式,我不知道如何在第二个控制器中使用services@elogriamine也许你可以做一些研究,如果答案有帮助的话,投票表决