我是AngularJS的新用户,正在制作单页应用程序。请参阅附加屏幕截图我有一个下拉菜单,其中有一个应用按钮,单击此按钮时,我想调用在不同控制器中编写的功能。我在一个shell页面上有多个下拉列表,我附上了TimeLine下拉列表的屏幕截图以供了解。基本上有三个下拉菜单,并且它们对于每个Tab都是相同的,这就是为什么我将它们放在shell页面中的原因。例如,有一个下拉菜单填充数据库中的所有客户端名称,并具有复选框,因此当用户选择多个复选框并单击应用按钮时,应使用新数据刷新这些下拉菜单下的视图。如何调用按钮上的控制器功能点击当我的按钮被放置在不同的控制器中时angularjs
//这个控制器功能用于从数据库中获取数据,并填补了下拉。
app.controller("FillDropDownController",function($scope,GetService,$rootScope){
$rootScope.loading = true;
// Calling Serivce Method here to get the data and fill dropdown
$scope.GetDropDownValues = GetService.GetAll("CommonApi", "GetDropDownValues").then(function (d) {
$scope.GetDropDowns = d;
$rootScope.loading = false;
});
// Here goes the function for ng-click = GetSelectedPractices() which gets the selected clients
$scope.GetSelectedPractices = function () {
$scope.selectedPractices = [];
angular.forEach($rootScope.PracticesList, function (d) {
if (d.selected == true) {
$scope.selectedClients.push(d.CLIENTNAME);
}
});
$scope.spanValues = $scope.selectedClients;
// I am stuck here that how to call controller functions for specific view
}
});
这里有两种不同的控制器功能(二者都更新相同的视图),其从数据库中获取数据并填充的表或绘制基于数据的图表。所有这些控制器函数调用通用服务来获取数据。我的问题是,如果您看到图像编号,我的应用按钮下拉列表放置在外壳页面中。 2页面上有标签,这个“时间轴”下拉对于所有标签是相同的(点击每个标签有一个视图被加载并且它的功能被调用并且在视图上显示表或绘制图表)。
app.controller("GetChargesController", function ($scope, GetService, $rootScope) {
$scope.Title = "Charges Details List";
$rootScope.loading = true;
// Calling Serivce Method here to get the data
$scope.GetChargesDetails = GetService.GetAll("CommonApi", "GetChargesDetails").then(function (d) {
$scope.ChargesDetails = d;
$rootScope.loading = false;
});
});
app.controller("GetPaymentsController", function ($scope, GetService, $rootScope) {
$scope.Title = "Payments Details List";
$rootScope.loading = true;
// Calling Serivce Method here to get the data
$scope.GetPaymentsDetails = GetService.GetAll("CommonApi", "GetPaymentsDetails").then(function (d) {
$scope.PaymentsDetails = d;
$rootScope.loading = false;
});
});
使用发射/广播事件 –