Last active
August 29, 2015 13:59
-
-
Save daver182/10977907 to your computer and use it in GitHub Desktop.
Getting data from a ASP Webservice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Then in the app.js file we set the interceptor | |
var app = angular.module('appName', ['xml']) | |
.config(function ($routeProvider, $httpProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: 'views/view1.html', | |
controller: 'Controller1', | |
}) | |
.when('/view2', { | |
templateUrl: 'views/view2.html', | |
controller: 'Controller2', | |
}) | |
.otherwise({ | |
redirectTo: '/' | |
}); | |
$httpProvider.responseInterceptors.push('xmlHttpInterceptor'); | |
}); | |
//And in some service, we make the request in parse the results | |
$http.post('http://url.to.server').then(function(response){ | |
var items = [], | |
els = response.xml.find('Table'), | |
item, | |
i; | |
for (i = 0; i < els.length; i += 1) { | |
item = angular.element(els[i]); | |
var children = item.children(); | |
items.push({ | |
id: children[0].childNodes[0].nodeValue, | |
name: children[1].childNodes[0].nodeValue, | |
password: children[2].childNodes[0].nodeValue, | |
email: children[3].childNodes[0].nodeValue, | |
phone: children[4].childNodes[0].nodeValue, | |
address: children[5].childNodes[0].nodeValue | |
}); | |
} | |
}, function(){ | |
console.log('An error ocurred'); | |
}); | |
return items; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--We are going to use this XML Module for Angularjs | |
//https://github.com/johngeorgewright/angular-xml--> | |
<!--We call the XML script before app.js--> | |
<html> | |
<head> | |
<script src="scripts/angular-xml/angular-xml.js"></script> | |
<script src="scripts/app.js"></script> | |
</head> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment