【发布时间】:2016-11-22 16:21:03
【问题描述】:
我是 AngularJS 的新手,正在制作单页应用程序。请查看随附的屏幕截图我有一个下拉菜单,其中有一个应用按钮,单击此按钮我想调用在不同控制器中编写的函数。我在 shell 页面上有多个下拉列表,我附上了 TimeLine 下拉列表的屏幕截图以供理解。基本上有三个下拉菜单,每个选项卡都是相同的,这就是我将它们放在 shell 页面中的原因。例如,有一个下拉列表从数据库中填充所有客户端名称并具有复选框,因此当用户选择多个复选框并单击“应用”按钮时,这些下拉列表下的视图应该用新数据刷新。
// 该控制器函数用于从数据库中获取数据并填充下拉列表。
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;
});
});
【问题讨论】:
-
使用发出/广播事件进行控制器之间的通信
标签: javascript angularjs angularjs-directive angularjs-scope