Angularjs angular js在另一个控制器方法中调用控制器的方法

Angularjs angular js在另一个控制器方法中调用控制器的方法,angularjs,angularjs-scope,angularjs-service,angularjs-controller,Angularjs,Angularjs Scope,Angularjs Service,Angularjs Controller,我正在angularjs中编写一个代码,根据会话需求加载控制器文件 我有一个单独的控制器文件,用于管理员(比如说ctrl1)和员工(ctrl2)和一个通用(ctrlComm)文件,可以使用其中的任何一个,现在我想调用ctrl1内部的函数,我不想再次编写或粘贴文件代码,我如何才能做到这一点。这是我的代码。 ctrl1: customerSupport.controller('studentSheet',['$scope',function($scope){ $scope.searchStuden

我正在
angularjs
中编写一个代码,根据会话需求加载
控制器
文件 我有一个单独的控制器文件,用于
管理员(比如说ctrl1)
员工(ctrl2)
和一个
通用(ctrlComm)
文件,可以使用其中的任何一个,现在我想调用
ctrl1
内部的
函数,我不想再次编写或粘贴文件代码,我如何才能做到这一点。这是我的代码。

ctrl1:

customerSupport.controller('studentSheet',['$scope',function($scope){

$scope.searchStudent=function(studentid){
        angService.getfromRemote('students/'+studentid)
            .success(function(response){
                if(response.success){
                        ...
                 }
           })
        }
    }])
ctrlComm

activities.controller('usersActivites',['$scope',function(){

$scope.studentdetail=function(studentid){
    console.log("how can i call the searchStudent if ctrl1 here ??");

    $scope.searchStudent(studentid);

   }


}])

共享一个功能是一个明确的信号,表明您需要一个

角度服务是使用连接在一起的可替换对象。您可以使用服务在应用程序中组织和共享代码


我相信您已经为此准备了
angService
。将此服务注入到
usersActivites
中,您就可以开始了。你可以调整你的服务,直接获取学生的详细信息。在那里创建一些函数,如
angService.searchStudent
,并从服务返回适当的响应。

相反,你应该在活动控制器中访问学生服务。如果它工作,我现在需要做的是,将我的控制器搜索函数写入服务中,然后它将在任何地方工作。再一次