1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| angular.module('angularSoap', [])
.factory("$soap",['$q',function($q){
return {
post: function(url, action, params){
var deferred = $q.defer();
//Create SOAPClientParameters
var soapParams = new SOAPClientParameters();
for(var param in params){
soapParams.add(param, params[param]);
}
//Create Callback
var soapCallback = function(e){
if(e.constructor.toString().indexOf("function Error()") != -1){
deferred.reject("An error has occurred.");
} else {
deferred.resolve(e);
}
}
SOAPClient.invoke(url, action, soapParams, true, soapCallback);
return deferred.promise;
}
}
}]);
angular.module('myApp', ['angularSoap'])
.factory("testService", ['$soap',function($soap){
var base_url = "http://localhost/ws_ldap/InputServer.php";
return {
getExternalI: function(){
return $soap.post(base_url, "getExternalI");
}
}
}])
.controller('MainCtrl', function ($scope, testService, $http) {
var oo = testService.getExternalI();
$http.get("oo",
{
transformResponse: function (cnv) {
var x2js = new X2JS();
var aftCnv = x2js.xml_str2json(cnv);
return aftCnv;
}
})
.then(function (response){
console.log(response);
$scope.myData = response;
});
}); |
Partager