I'm really newbie on angularjs, I'm trying to display a list of products so I call a service with $http and in the success function populate the $scope. All seems works, the $scope.list contains the products but nothing is displayed
I already had a look at this Angularjs $http.get().then and binding to a list and everything looks the same except the "then" function that in my case should be the success function, I suppose. (because if I add that function I get $http(...).then(...).error is not a function).
<div ng-app="myApp" ng-controller="myCtrl">
<ul class="example-animate-container">
<li class="animate-repeat" ng-repeat="item in $scope.list as results">
item {{$index + 1}}:
{{item.Brand}}
</li>
<li class="animate-repeat" ng-if="results.length == 0">
<strong>No results found...</strong>
</li>
</ul>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
var url = "http://localhost:50083/service.asmx/StylesMock";
$scope.list = new Array();
$http({method: 'POST', url: url, headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }})
.success(function(xmlString){
var parser = new DOMParser();
var xml = parser.parseFromString(xmlString, "text/xml");
jsonData = xmlToJson(xml);
mapToScope($scope, jsonData);
})
.error(function(data, status, headers, config) { alert("error"); });;
function mapToScope($scope, data){
angular.forEach(data.ArrayOfStyleData.StyleData, function(value, key) {
$scope.list.push({
Brand : value.Style.Brand,
Name : value.Style.Name,
Image : value.Style.Image,
Price : value.Style.StylePrice
});
});
}
});
Any idea? Is there a way to understand where the problem is? the console doesn't display errors