1

我遇到了我的Angular Wine應用程序的問題。問題是我已經在單個控制器中使用了所有的東西,現在我想分割它們並且我已經完成了,但是我的數據不會顯示。所以我在尋找一些幫助。不顯示我的葡萄酒與服務

我得到我的所有對象,我應該和一切似乎都很好,除了數據沒有顯示。任何人都可以幫忙嗎?

的HTML:

<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>Name</th> 
     <th>Description</th> 
     <th>Year</th> 
     <th>Price</th> 
     <th>&nbsp;</th> 
    </tr> 
    </thead> 



<tbody> 
    <tr ng-repeat="wine in wines"> 
     <td><img ng-src="{{wine.Vineyard.ImageUrl}}" style="width: 100px; margin: 5px;" />{{wine.Name}}</td> 
     <td style="width: 250px;">{{wine.Description}}</td> 
     <td>{{wine.Vintage}}</td> 
     <td>{{wine.PriceRetail | currency}}</td> 
     <td> 
      <button ng-click="selectWine(wine)" class="btn btn-warning"><span class="glyphicon glyphicon-pencil"></span></button> 
      <button ng-click="removeWine(wine)" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span></button> 
      <button ng-click="favWine(wine)" class="btn btn-info"><span class="glyphicon glyphicon-star"></span></button> 
      <button ng-click="detailWine(wine)" class="btn btn-default"><span class="glyphicon glyphicon-zoom-in"></span></button> 
     </td> 
    </tr> 
</tbody> 

而且AngularJS從winedata文件

WineApp.controller("ListController", function($scope, $http, winedata) { 
$scope.wines = winedata.getWines(); 

$scope.removeWine = function(wine) { 
    // console.log("remove wine"); 

    var index = $scope.wines.indexOf(wine); 
    // console.log(index); 

    $scope.wines.splice(index, 1) 
} 

$scope.selectWine = function(wine) { 
    $scope.wine = wine; 
} 

$scope.updateWine = function(wine) { 
    // var editWine = { 
    // Name: $scope.wine.Name, 
    // Description: $scope.wine.Description, 
    // Vintage: $scope.wine.Vintage, 
    // PriceRetail: $scope.wine.PriceRetail 
    // } 
    $scope.wine = wine; 
    // console.log(wine); 
    // $scope.wines.extend(editWine); 
    alert("Updated!"); 
    // $scope.wine.Name = ""; 
    // $scope.wine.Description = ""; 
    // $scope.wine.Vintage = ""; 
    // $scope.wine.PriceRetail = ""; 
} 
}); 

)它應該是從

WineApp.service('winedata', function($http) { 

this.getWines = function() { 
$http.get("http://services.wine.com/api/beta2/service.svc/json/catalog?apikey=2aef2f70e044ebcb683f46df93ac4eb9&size=100") 
.success(function(response) { 
    // alert(response); 
    console.log(response.Products.List); 

    wines = response.Products.List; 
}) 
} 


this.searchForWine = function(Name) { 
     $http.get("http://services.wine.com/api/beta2/service.svc/json/catalog?apikey=2aef2f70e044ebcb683f46df93ac4eb9&size=100&search=" + Name) 
     .success(function(response) { 
      // alert(response); 
      console.log(response.Products.List); 

      wines = response.Products.List; 
     }) 
} 
// wines.favoriteWine = []; 
}); 
+0

我應該說路由工作正常,它只是沒有顯示的數據 –

回答

1

獲取數據的功能getWine(服務服務似乎沒有任何回報。試着用

return response.Products.Lists; 

更換

wines = response.Products.Lists; 

,你應該罰款。

+0

我試圖做到這一點,所以它看起來像這樣: –

+0

WineApp.service('winedata',function($ http) { this.getWines =函數(){$ http.get( 「http://services.wine.com/api/beta2/service.svc/json/catalog?apikey=2aef2f70e044ebcb683f46df93ac4eb9&size=100」) .success (功能(響應){// 警報(響應); 的console.log(response.Products.List); // successcb(響應); 返回response.Products.List; }) } –

+0

和它仍然沒有工作(apoligies,這是不是在同一職位:)) –