I'm having difficulty returning data from my service to my view in AngularJS. Here is what I have at the moment. I also tried something like this, but had the same result. AngularJS Load Data from Service
Controller
.controller('ClassCtrl', ['$scope', '$stateParams', 'ClassService', function($scope, $stateParams, ClassService) {
$scope.data = ClassService.getClass($stateParams.siteID, $stateParams.classDate, $stateParams.classID);
$scope.$apply(); // I thought this my do it?
}])
Service
.factory('ClassService', ['$http', function ($http) {
return {
getClass: function(parm1, parm2, parm3) {
var classData = {};
var url = 'http://somesoapservice.com';
var sr = '<?xml version="1.0" encoding="UTF-8"?>' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
'moresoapstuff' +
'</soap:Body>' +
'</soap:Envelope>';
$http({
method: 'POST',
url: url,
data: sr,
headers: {
'Content-type': 'text/xml',
'SOAPAction': 'http://somesoapservice/soapaction'
}
}).
success(function (data, status, headers, config) {
var classDetail = $(data).find('Class');
var staffFirst = classDetail.find('Staff').find('FirstName').text();
//alert(staffFirst); // This displays the first name. Great!
classData = {
staffFirst: staffFirst
};
return classData;
}).
error(function(data, status, headers, config) {
alert('Error!');
});
return classData;
}
}
}])
View
<view title="navTitle" right-buttons="rightButtons">
<content has-header="true" has-footer="true">
First Name: {{data.staffFirst}}
</content>
</view>
I can see staffFirst in an alert when put inside the service, but cannot get it to appear in my view.