2017-03-03 11 views
-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のボランティアがあなたを助けるのは難しいです。あなたは、質問自体にそれを再現するのに必要な、_特定の問題_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ – lealceldeiro

+0

'サービス 'とは何ですか?それはどこに定義されていますか?ブラウザのコンソールにエラーが表示されていませんか? –

+0

ありがとう、私は自分のエラーを追加した、私は自分のコードは非常にシンプルだと思う、なぜwebapiからデータを取得しないでください。 – qianli

答えて

0

タイプミスがあり、あなたは空のオブジェクトを返します。 Service.getCustomersdatafactory.getCustomersに変更してください。