In my code i use angular (material) autocomplete and i need to get data from external php file.
HTML:
<md-autocomplete
md-selected-item="selectedItem"
md-search-text="searchText"
md-items="item in getInterest1(searchText)"
md-item-text="item.name"
placeholder="Search for a vegetable">
<span md-highlight-text="searchText">{{item.name}} :: {{item.type}}</span>
</md-autocomplete>
//RETURN: results [{"name":"Broccoli","type":"Brassica"}]
$scope.getInterest1 = function() {
var results = [
{
'name': 'Broccoli',
'type': 'Brassica'
}];
console.log('results', JSON.stringify(results));
return results;
};
But when i call the same JSON using $http.get it doesn’t show results in autocomplete and nothing happends.
//RETURN: results [{"name":"Broccoli","type":"Brassica"}]
$scope.getInterest2 = function() {
$http.get("../inc/users/search_interest.php?query=" + $scope.searchText)
.success(function(results) {
//$scope.interest = results;
console.log('results', JSON.stringify(results));
return results.data;
});
};
But i can see in console that results are equals.
In my php file (which is called by $http.get) i return JSON with json-encode:
$row_set = array('name' => 'Broccoli', 'type'=> 'Brassica');
echo json_encode(array($row_set));
Maybe php json_encode return a bad formed json?
Thanks