Get XML feed from external file using AngularJS
I'm trying to get an XML feed from the same domain, but obj is returning null. Below is my code.
Service
angular.module('ngAuidApp')
.service('profileInfoService', function($http){
return $http.get('scripts/user-feed.xml');
});
controller
angular.module('ngAuidApp')
.controller('ProfileCtrl', ['$scope', 'x2js', 'profileInfoService', function ($scope, x2js, profileInfoService) {
var xmlObj = '<feed><title type="text">User Ashish Panchal - Stack Overflow</title><link rel="self" href="http://stackoverflow.com/feeds/user/3635285" type="application/atom+xml" /><link rel="alternate" href="http://stackoverflow.com/users/3635285" type="text/html" /></feed>';
var jsonOb = x2js.xml_str2json(xmlObj);
// Prints title from above xml string
console.log(jsonOb.feed.title);
// Trying to fetch from external file
profileInfoService.success(function(data){
// Print outs xml feed
console.log(data);
var jsonObj = x2js.xml_str2json(data);
// Prints null
console.log(jsonObj);
});
}]);
When I try to get the feed from an external file it gives null. Can someone please advise me what is missing?
+3
source to share