I want to show on the browser page my array returned from elasticsearch.
I have this js file: (search.js)
var RicercaApp = angular.module("ricercaApp", ['elasticsearch']);
RicercaApp.service("search", ['$http',
function($http)
{
this.elencoPersone = [];
this.ricerca = 'http://localhost:9200/_search?q=Cognome:';
this.cercaCognome = function(cognome)
{
this.ricerca = this.ricerca + cognome;
this.elencoPersone = $http.get(this.ricerca)
.success(function(response)
{
this.elenco = response.hits.hits;
// Test: stampa in console
angular.forEach(this.elenco,
function(item)
{
console.log(item._source.Anagrafica.Nome + " " + item._source.Anagrafica.Cognome);
}
)
return this.elenco;
})
.error(function() {
console.log("error");
});
this.ricerca = 'http://localhost:9200/_search?q=Cognome:';
};
}]
)
RicercaApp.controller("searchController",
function($scope, search)
{
console.log("searchController");
$scope.persona = {cognome: $scope.cognome};
$scope.cercaPersona = function()
{
search.cercaCognome(this.persona.cognome);
};
}
)
RicercaApp.controller("elencoController",
function($scope, search)
{
$scope.elencoPersone = search.elencoPersone;
}
);
and my html file:
<html>
<head>
<title>Ricerca Anagrafica</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/elasticsearch/5.0.0/elasticsearch.angular.min.js"></script>
<script src="search.js"></script>
</head>
<body ng-app="ricercaApp">
<div ng-controller="searchController">
<h1>Ricerca</h1>
Filtra per cognome: <input type="text" ng-model="persona.cognome">
<button ng-click="cercaPersona()">Ricerca</button>
<p ng-if="persona.cognome">Clicca "Ricerca" per ottenere i risultati su: <b>{{persona.cognome}}</b></p>
</div>
<div ng-controller="elencoController">
<ul>
<li ng-repeat="person in elencoPersone">{{person._source.Anagrafica.Nome}} {{person._source.Anagrafica.Cognome}}</li>
</ul>
</div>
</body>
The program print the array on the console, but not on the page. How can I print my array on the browser page? Do you have any advice? Thanks.