Javascript 如何在AngularJS中将$broadcast函数发送给其他控制器?

Javascript 如何在AngularJS中将$broadcast函数发送给其他控制器?,javascript,angularjs,kendo-treeview,Javascript,Angularjs,Kendo Treeview,我有三个屏幕,每个屏幕都有相同的位置树视图下拉功能,我在下面的函数中实现了这个功能,现在我想在需要位置树视图下拉的任何应用程序中使用它。假设我有另一个控制器Ctrl2.js,我如何使用Ctrl1.js中的updateGeolocationList()函数。任何帮助都将不胜感激 Ctrl1.js $scope.updateGeoLoctionList = function(geoLocation){ var pos = $.inArray(geoLocation.text, sel

我有三个屏幕,每个屏幕都有相同的位置树视图下拉功能,我在下面的函数中实现了这个功能,现在我想在需要位置树视图下拉的任何应用程序中使用它。假设我有另一个控制器Ctrl2.js,我如何使用Ctrl1.js中的updateGeolocationList()函数。任何帮助都将不胜感激

Ctrl1.js

$scope.updateGeoLoctionList = function(geoLocation){
        var pos = $.inArray(geoLocation.text, selectedGeoLocations);

        if(pos < 0){
            selectedGeoLocations.push(geoLocation.text);
            selectedGeoLocationIds.push(geoLocation.id);
            //if Global is checked disable all parent and children
            if (geoLocation.id === 5657){
              $.each(geoLocation.parent(),function(index,location) {
                if (location.id !== geoLocation.id) {
                  $.each(location._childrenOptions.data.items,function(index,child){
                    var disableChildId = 'disabled' + child.id;
                    var model = $parse(disableChildId);
                      model.assign($scope, true);
                  })
                  var disableItemId = 'disabled' + location.id;
                  // Get the model
                  var model = $parse(disableItemId);
                  // Assigns a value to it
                  model.assign($scope, true);

                }
              });
            }
}
$scope.updateGeoLoctionList=函数(地理位置){
var pos=$.inArray(geoLocation.text,selectedGeoLocations);
如果(位置<0){
选择geolocations.push(geoLocation.text);
选择geolocationids.push(geoLocation.id);
//如果选中“全局”,则禁用所有父级和子级
如果(geoLocation.id==5657){
$.each(geoLocation.parent(),函数(索引,位置){
if(location.id!==geoLocation.id){
$.each(位置._childrenOptions.data.items,函数(索引,子项){
var disableChildId='disabled'+child.id;
var模型=$parse(disableChildId);
model.assign($scope,true);
})
var disableItemId='disabled'+location.id;
//获取模型
var模型=$parse(disableItemId);
//给它赋值
model.assign($scope,true);
}
});
}
}
Config.js

geoLocationTreeConfig : {
        template: '{{dataItem.text}}',
        checkboxes: {
            checkChildren: false,
           template: '<input ng-disabled=\'disabled#: item.id #\' type=\'checkbox\' ng-click=\'updateGeoLoctionList(dataItem)\' value=\'true\' />'
        }
    },controlInPrcsGeoLocationTreeConfig : {
        template: '{{dataItem.text}}',
        checkboxes: {
            checkChildren: false,
            template: '<input  {{dataItem.disabled}} type=\'checkbox\' ng-click=\'populateControlInPrcsGeoLoction(dataItem)\' value=\'true\' />'
        }
    },riskInPrcsGeoLocationTreeConfig : {
        template: '{{dataItem.text}}',
        checkboxes: {
            checkChildren: false,
            template: '<input  ng-disabled=\'disabled#: item.id #\' type=\'checkbox\' ng-click=\'populateRisToProcesskGeoLoctionList(dataItem)\' value=\'true\' />'
        }
    }
geoLocationTreeConfig:{
模板:{{dataItem.text}},
复选框:{
checkChildren:false,
模板:“”
}
},controlInPrcsGeoLocationTreeConfig:{
模板:{{dataItem.text}},
复选框:{
checkChildren:false,
模板:“”
}
},riskInPrcsGeoLocationTreeConfig:{
模板:{{dataItem.text}},
复选框:{
checkChildren:false,
模板:“”
}
}
您可以使用$broadcast或$emit(气泡向上,vs向下),但我认为更好的模式是将其移动到它自己的指令中。然后您可以将该指令包含到您想要的任何html中。在该指令中包含ng click,每当用户单击该元素时,就会出现下拉列表


但是如果没有更多的信息/代码,就很难完全理解您的意图,因为这只是一个配置对象和一个控制器的函数。但是这里有一个指向kindo树视图角度页面的链接,以获取更多信息:

当您想在其他应用程序和指令中使用
updateGeoLoctionList
时,最好的解决方案是将其绑定到服务中。然后可以将该服务注入到指令、控制器或其他服务中以供使用