現在、2つのjavascriptコントローラー、selectAllとlistAllDomainsがあります。私は下のコントローラのSelectAll方法getBeanName(listAllDomainsで定義されている)を呼び出すようにしようとしている :注意点としてanglejs内の別のコントローラーから関数を呼び出す
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