angularjs
  • debugging
  • 2017-03-03 52 views -1 likes 
    -1

    此代碼用於從我的web api獲取數據,但它不起作用。我一次又一次地檢查,但注意到發生了。請幫助我,不管我手上有錯誤的代碼?爲什麼我的角度js代碼不起作用

    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; 
          }); 
         } 
        }]); 
    

    這裏是從瀏覽器中的錯誤: enter image description here

    +0

    像_ _「爲什麼這個代碼不起作用?」_/_「爲什麼我會得到這個錯誤」這樣的問題_志願者對SO很難幫助你。您應該在問題本身中包含所需的行爲_,特定的問題或錯誤_以及必須重新生成_shortest code_。 – lealceldeiro

    +0

    什麼是「服務」?它在哪裏定義?你沒有注意到你的瀏覽器控制檯中的錯誤? –

    +0

    非常感謝,我添加了我的錯誤,我認爲我的代碼非常簡單,爲什麼不從WebAPI獲取數據。 – qianli

    回答

    0

    有一個錯字,你返回一個空的對象。將Service.getCustomers更改爲datafactory.getCustomers

    相關問題