Can't get data outside a service function

bakowroc

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?

Riddhi Gohil

Change your file and try:

Add "return" before "$http.get/$http.post"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't I get the geolocation just outside that function

From Java

Can't get access to Data Hub Service using Java API

From Dev

Can't get data from my generated web service

From Dev

Can't use variables outside of function in javascript

From Dev

Can't move variables outside of a function

From Dev

Can't get data from table using function belongsToMany

From Dev

Can't get data from table using function belongsToMany

From Dev

Why can't I refactor this anonymous function outside the enclosing function?

From Dev

I can't seem to get a service to return data to a controller if data is pulled from json file

From Dev

How can I get clientHeight value outside backbone render function?

From Dev

How can I get the dimensions of the view outside a function?

From Dev

How I can get the value of "j" for use outside the function?

From Dev

How can I get clientHeight value outside backbone render function?

From Dev

Service can't reach post function

From Dev

Can't use variable outside function even after setting it global

From Dev

Can't connect function imported outside of class qt

From Dev

I can't use a variable outside of Wordpress shortcode function

From Dev

Can't access variable outside the function scope in JS

From Dev

Can't reach results of Papa Parse outside the 'complete' function

From Dev

Can't get function .on("click")

From Dev

Javascript: get `this` outside the function

From Dev

Angular2: Can't get data from service after refreshing page on child component

From Dev

How can I get Quote data outside Magento API?

From Dev

How can i get data outside a foreach loop in javascript?

From Dev

Java how can I get a row of Json data outside of the for loop

From Dev

laravel-soap - can't get the response outside of the wrapper

From Dev

can't get ArrayList outside of for loop in call.enqueue

From Dev

Can't get textilate.js to work outside default settings

From Dev

Can't get Jquery to work correctly outside of JSFiddle

Related Related

  1. 1

    Why can't I get the geolocation just outside that function

  2. 2

    Can't get access to Data Hub Service using Java API

  3. 3

    Can't get data from my generated web service

  4. 4

    Can't use variables outside of function in javascript

  5. 5

    Can't move variables outside of a function

  6. 6

    Can't get data from table using function belongsToMany

  7. 7

    Can't get data from table using function belongsToMany

  8. 8

    Why can't I refactor this anonymous function outside the enclosing function?

  9. 9

    I can't seem to get a service to return data to a controller if data is pulled from json file

  10. 10

    How can I get clientHeight value outside backbone render function?

  11. 11

    How can I get the dimensions of the view outside a function?

  12. 12

    How I can get the value of "j" for use outside the function?

  13. 13

    How can I get clientHeight value outside backbone render function?

  14. 14

    Service can't reach post function

  15. 15

    Can't use variable outside function even after setting it global

  16. 16

    Can't connect function imported outside of class qt

  17. 17

    I can't use a variable outside of Wordpress shortcode function

  18. 18

    Can't access variable outside the function scope in JS

  19. 19

    Can't reach results of Papa Parse outside the 'complete' function

  20. 20

    Can't get function .on("click")

  21. 21

    Javascript: get `this` outside the function

  22. 22

    Angular2: Can't get data from service after refreshing page on child component

  23. 23

    How can I get Quote data outside Magento API?

  24. 24

    How can i get data outside a foreach loop in javascript?

  25. 25

    Java how can I get a row of Json data outside of the for loop

  26. 26

    laravel-soap - can't get the response outside of the wrapper

  27. 27

    can't get ArrayList outside of for loop in call.enqueue

  28. 28

    Can't get textilate.js to work outside default settings

  29. 29

    Can't get Jquery to work correctly outside of JSFiddle

HotTag

Archive