我目前有2个javascript控制器:selectAll和listAllDomains。 我试图调用该方法getBeanName(在listAllDomains定义)控制器全选下:在angularjs中调用另一个控制器的函数
response = $http.post('/invoke/selectAll/', INSERT_CALL_HERE);
作为一个说明,该方法getBeanName将作为参数传递给$ HTTP传递返回的对象。 post()方法并由Java控制器处理。
app.controller('listAllDomains', ['$http', '$scope', '$rootScope', function ($http, $scope, $rootScope) {
$scope.showSpinner = true;
$scope.showBtn = false;
let dataObj;
$http.get('domains/').then(function (response) {
$scope.showSpinner = false;
$scope.domains = response.data;
});
$scope.showButton = function(eleStatus) {
let eleSize = Object.keys(eleStatus).length;
return !eleSize;
};
$scope.getBeanName = function (objectType, objectName) {
dataObj = {
type : objectType,
name : objectName,
methodName : "select",
methodParameters : ["true"]
};
localStorage.setItem("dataObj", dataObj);
console.log(dataObj);
$rootScope.$emit("invokeSelectAll", dataObj);
return dataObj;
}
}]);
app.controller('selectAll', ['$http', '$scope' , '$rootScope',
function ($http, $scope, $rootScope) {
var response;
$rootScope.$on("invokeSelectAll", function(){
$scope.invokeSelectAll();
});
$scope.invokeSelectAll = function(){
console.log(localStorage.getItem("dataObj"));
response = $http.post('/invoke/selectAll/', INSERT_CALL_HERE);
response.success(function(data, status, headers, config) {
$scope.responses = data ? data : "Select Operation not supported on this bean";
});
}
}]);
任何帮助,将不胜感激!谢谢!
控制器之间的任何父子关系? – Rahul
定义服务中的getBeanName方法,并将该服务注入到两个控制器中。然后你可以从你注入服务的任何控制器中调用它。 –
[在AngularJS控制器之间共享数据]的可能的副本(https://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers) – anoop