我想知道如何将此控制器范围内的变量传递给另一个控制器。我想要做的是采取vm.search(searchParameters)并将其传递给另一个控制器。
///
(function(){ 'use strict';
var controllerId = 'GroupMaintenanceBrowsePlansCtrl';
angular.module('myApp').controller(controllerId, ['$scope', 'RenewalGroupDataService', 'logger', Controller]);
function Controller($scope, datacontext, logger) {
logger = logger.forSource(controllerId);
var logError = logger.logError;
var logSuccess = logger.logSuccess;
var logWarning = logger.logWarning;
var vm = {};
$scope.vm = vm;
vm.getPlans = getPlans;
vm.plans;
vm.loadingPlans = false;
vm.pageSize = 100;
function getPlans(searchParameters) {
vm.loadingPlans = true; vm.search = searchParameters;
datacontext.getAssignedPlans(searchParameters, vm.pageSize).then(function (plans) {
vm.plans = plans;
//Compares which columns are being populated for choosing which headings to show
if (vm.search.MchNumber != null
||vm.search.ContractNumber != null
|| vm.search.PlanCode != null)
{
vm.detail = true;
}
if (vm.search.DivisionName != null
|| vm.search.PoolName != null
|| vm.search.SubpoolName != null
|| vm.search.RenewalGroupName != null)
{
vm.detail = false;
}
//Sets values to NULL after every search is performed
vm.search.MchNumber =
vm.search.ContractNumber =
vm.search.PlanCode =
vm.search.DivisionName =
vm.search.PoolName =
vm.search.SubpoolName =
vm.search.RenewalGroupName = null;
}).finally(function () { vm.loadingPlans = false; });
}
};
})();
答案 0 :(得分:0)
要使用两个控制器之间的值,您可以使用两个控制器都注入的服务。
e.g。
root.service("MyService", function () {});
将MyService
注入每个控制器。然后两个控制器将使用相同的实例(因为服务是单例),因此您在该服务上更改的任何内容都将被共享。
您也可以将服务放在$scope
上并使用模板绑定。但在你的情况下,我并不认为这是相关的。