Sunucumdan bilgi içeren bir json döndürmek için hizmetime ihtiyacım var. hizmetinAngularJS hizmetinde bir nesne türü döndürülemiyor
Kodu:
app.service('Server', function() {
this.fetch = function (data, token) {
fetch('http://104.197.58.108:8080', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
data: data,
token: token
})
})
.then(function(response) {
return response.json()
}).then(function(text) {
if (text.success == false) {
return false;
} else {
return text;
}
})
}
})
İşte denetleyicisinden kod.
$scope.data2 = '{"func":"materialSons","material":"0"}';
console.log(Server.fetch($scope.data2, $rootScope.token));
$scope.materialist = Server.fetch($scope.data2, $rootScope.token);
Sunucu başarılarını isteme, ancak işlev tanımsız olarak döndürür.
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
Geri getirme yöntemine bir geriçağırım işlevi sağlama –