I wrote an angular service with couple functions as below
(function () {
var app = angular.module('services', []);
app.factory('dataManage', ['$http', function ($http) {
var _get = function (table, callback, id = null) {
callback = callback || function () {};
$http.get('php/app.php/?type=get&table=' + table + '&id=' + id)
.success(function (data) {
callback(data);
});
};
var _insert = function (table, object, callback, id = null) {
callback = callback || function () {};
$http.post('php/app.php?type=insert&table=' + table + '&id=' + id, object)
.success(function (data) {
callback(data);
});
}
var _check = function (action, callback, object = null) {
callback = callback || function () {};
$http.post('php/app.php?type=check&action=' + action, object)
.success(function (data) {
callback(data);
});
}
return {
Get: _get,
Insert: _insert,
Check: _check
};
}]);
})();
and it's called in app.js
dataManage.Get('meetings', function (data) {
$scope.meetings = data.slice();
});
I've got access to meetings from html code but I can't manage it outside the service. For example if i'd like to alert it or show in console the result shows undefined or empty array( if defined before as it).
No idea what's going on. As I remember I haven't got this problem in my previous projects... Anyone?
Change your file and try:
Add "return" before "$http.get/$http.post"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments