why my angular js code does not work

qianli

This code is used to fetch the data from my web api, but it does not work. I have checked again and again, but noting happened. please help me, whether I hand a wrong code?

var MyApp = angular.module("MyApp", []);
    MyApp.factory('Service', ['$http', function ($http) {
        var urlBase = 'http://localhost:1883/api';
        var datafactory = {};
        Service.getCustomers = function () {
            return $http.get(urlBase + '/Customers1');
        };
        return datafactory;
    }]);

    MyApp.Controller('UpdateController', ['$scope', 'datafactory', function ($scope, datafactory) {
        getCustomers();

        function getCustomers() {
            datafactory.getCustomers()
            .then(function (data) {
                $scope.customers = data;
            }, function (error) {
                $scope.status = 'Unable to load customer data: ' + error.message;
            });
        }
    }]);

here is the error from browser: enter image description here

Maxim Goncharuk

There is a typo, you return an empty object. Change Service.getCustomers to datafactory.getCustomers.

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 does my Matlab code not work correctly?

From Dev

why my angular code doesnt work?

From Dev

Angular resource does not work on my code

From Dev

Why does my code work with underscore.js but not when I use Ramda.js?

From Dev

Why does my code work with underscore.js but not when I use Ramda.js?

From Dev

How does this Angular JS code snippet work?

From Dev

Why does not work two controller in Angular JS?

From Dev

Why Angular js Service does not work?

From Dev

Why does my code not work on a device, but work on the emulator?

From Dev

why does my html code ignores my js?

From Dev

Warning: implicit declaration of function — why does my code work anyway?

From Dev

Arduino. Why does my code work with a delay

From Dev

Why does my code only work properly one time?

From Dev

Why does this code work on my test server but not on jsfiddle?

From Dev

Why does my PHP code doesn't work anymore for no reason?

From Dev

why does my jquery code not work on mobile browser

From Dev

Why my Java multithreading code does not work properly?

From Dev

Why does my Sobel edge detection code not work?

From Dev

Why does my search php code not work properly?

From Dev

Why does my code work only on Virtual Server?

From Dev

Apply CSS upon query string - My code does not work, but why?

From Dev

Why does my template not work in angular2 component?

From Dev

Why does my JS script work but not the same C#?

From Dev

Why does my three.js lighting not work?

From Dev

Why won't my simple Angular.js app work?

From Dev

Why does my Kivy BoxLayout not work at the top of my code but it does at the bottom?

From Dev

Why does not work custom options in Angular JS Dropdown Multiselect?

From Dev

Why this simple Angular.js example does not work?

From Dev

why does'nt my js code reflect the right runtime value?

Related Related

  1. 1

    Why does my Matlab code not work correctly?

  2. 2

    why my angular code doesnt work?

  3. 3

    Angular resource does not work on my code

  4. 4

    Why does my code work with underscore.js but not when I use Ramda.js?

  5. 5

    Why does my code work with underscore.js but not when I use Ramda.js?

  6. 6

    How does this Angular JS code snippet work?

  7. 7

    Why does not work two controller in Angular JS?

  8. 8

    Why Angular js Service does not work?

  9. 9

    Why does my code not work on a device, but work on the emulator?

  10. 10

    why does my html code ignores my js?

  11. 11

    Warning: implicit declaration of function — why does my code work anyway?

  12. 12

    Arduino. Why does my code work with a delay

  13. 13

    Why does my code only work properly one time?

  14. 14

    Why does this code work on my test server but not on jsfiddle?

  15. 15

    Why does my PHP code doesn't work anymore for no reason?

  16. 16

    why does my jquery code not work on mobile browser

  17. 17

    Why my Java multithreading code does not work properly?

  18. 18

    Why does my Sobel edge detection code not work?

  19. 19

    Why does my search php code not work properly?

  20. 20

    Why does my code work only on Virtual Server?

  21. 21

    Apply CSS upon query string - My code does not work, but why?

  22. 22

    Why does my template not work in angular2 component?

  23. 23

    Why does my JS script work but not the same C#?

  24. 24

    Why does my three.js lighting not work?

  25. 25

    Why won't my simple Angular.js app work?

  26. 26

    Why does my Kivy BoxLayout not work at the top of my code but it does at the bottom?

  27. 27

    Why does not work custom options in Angular JS Dropdown Multiselect?

  28. 28

    Why this simple Angular.js example does not work?

  29. 29

    why does'nt my js code reflect the right runtime value?

HotTag

Archive