2017-04-12 71 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或接受答案;) –