텔레콤 앱 대시 보드를 만듭니다. Logstash 및 Elastic 검색을 사용하여 로그를 가져 와서 Angularjs의 ng-Table 지시문을 사용하여 UI에 표시하려고합니다.다른 모듈의 컨트롤러간에 데이터 전달
로그를 얻을 수 있지만 문제는 다른 모듈의 두 컨트롤러간에 응답을 보내는 것입니다. 여기
탄성 검색에서 로그를 검색, 코드입니다 : 우리는 데이터가 QueryController에서 얻은 안타를 즉 전달해야
// We define an EsConnector module that depends on the elasticsearch module.
var EsConnector = angular.module('EsConnector', ['elasticsearch']);
// Create the es service from the esFactory
EsConnector.service('es', function (esFactory) {
return esFactory({ host: 'localhost:9200' });
});
// We define an Angular controller that returns the server health
// Inputs: $scope and the 'es' service
EsConnector.controller('ServerHealthController', function($scope, es) {
es.cluster.health(function (err, resp) {
if (err) {
$scope.data = err.message;
} else {
$scope.data = resp;
}
});
});
// We define an Angular controller that returns query results,
// Inputs: $scope and the 'es' service
EsConnector.controller('QueryController', function($scope, es) {
// search for documents
es.search({
index: 'logstash-2014.08.29',
size: 500,
body: {
"query":
{
"match": {
"CallId":-1 }
},
}
}).then(function (response) {
$scope.hits = response.hits.hits;
});
});
(의 EsConnector 모듈) MainController에 (응용 프로그램의 모듈) 여기
앱 모듈입니다 : -
var app = angular.module('SnapshotApp',['ngTable']);
app.controller('MainController', function($scope, ngTableParams){
$scope.query = {}
$scope.queryBy = '$'
var data = ; \\ we want to populate 'data' with 'hits' of QueryController
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
});
두 가지 방법은 두 모듈을 병합하는 것입니다.
감사합니다.
이것은 aa 모듈 내의 두 컨트롤러 용입니다. 두 모듈간에 데이터를 전송하려면 어떻게해야합니까? –