我是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;
});
});
使用發射/廣播事件 –