2017-04-12 54 views
-1

我在AngularJ中運行測試,但是這個錯誤在控制檯中出現!在angularJs中獲取錯誤

Error: [filter:notarray] Expected array but received: {"data":[{"brand":"Samsung A7 Prime","color":"Gold","price":24500,"img":"img/Chrysanthemum.jpg"},{"brand":"iPhone 6 Plus","color":"White","price":29899,"img":"img/Desert.jpg"},{"brand":"Acer Liquid Zest","color":"Silver","price":6999,"img":"img/Hydrangeas.jpg"},{"brand":"HTC Desire 107","color":"Black","price":15799,"img":"img/Koala.jpg"}],"status":200,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"data/items.json","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"OK"} 
    http://errors.angularjs.org/1.6.3/filter/notarray?p0=%7B%22data%22%3A%5B%7B…son%2C%20text%2Fplain%2C%20*%2F*%22%7D%7D%2C%22statusText%22%3A%22OK%22%7D 
     at angular.js:66 
     at angular.js:20683 
     at fn (eval at compile (angular.js:15351), <anonymous>:4:299) 
     at regularInterceptedExpression (angular.js:16459) 
     at Scope.$digest (angular.js:18002) 
     at Scope.$apply (angular.js:18280) 
     at done (angular.js:12378) 
     at completeRequest (angular.js:12604) 
     at XMLHttpRequest.requestLoaded (angular.js:12532) 

JSON

[{ 
    "brand": "Samsung A7 Prime", 
    "color": "Gold", 
    "price": 24500, 
    "img": "img/Chrysanthemum.jpg" 
}, { 
    "brand": "iPhone 6 Plus", 
    "color": "White", 
    "price": 29899, 
    "img": "img/Desert.jpg" 
}, { 
    "brand": "Acer Liquid Zest", 
    "color": "Silver", 
    "price": 6999, 
    "img": "img/Hydrangeas.jpg" 
}, { 
    "brand": "HTC Desire 107", 
    "color": "Black", 
    "price": 15799, 
    "img": "img/Koala.jpg" 
}] 

的JavaScript

$http.get('data/items.json').then(function(data){ 
     $scope.items = data; 
    }); 

HTML

<ul class="list-group"> 
         <li class="list-group-item" ng-repeat="item in items | filter: search | orderBy: order"> 
          <img style="width: 50px; height: 50px; margin: 5px;" ng-src="{{item.img}}"> 
          {{item.brand}} -- {{item.color}} -- {{item.price | currency: 'Php '}} 
          <button class="btn btn-danger" ng-click="removeItem()">Remove Item</button> 
         </li> 
        </ul> 
+0

還是錯誤:'( –

+1

嘗試'$ scope.items = data.data' –

+0

它woooooooorks!謝謝MAAAAN:* –

回答

0

響應數據將出現在PROPERT稱爲數據,從而改變

$http.get('data/items.json').then(function(data){ 
     $scope.items = data.data; 
    }); 
+0

它woooooorks!謝啦。你最好的 –

+0

很高興聽到它。你可以upvote或接受答案;) –