我有一個其中有一個數組JSON文件:AngularJS HTTP服務參數
{
"people": [
{"number":"1", "name":"Gary", "surname":"Peterson", "age":"25"},
{"number":"2", "name":"Andy", "surname":"Smith", "age":"26"},
{"number":"3", "name":"Michael", "surname":"Johnson", "age":"28"}
]
}
我只想返回第一個對象(人記錄)我的應用程序。 當我調用AngularJS HTTP服務,並傳遞參數,如:
angular.module('mod', [])
.controller('ctrl', function($scope, $http){
$scope.serviceMethod = function(){
$http.get("url to database.json", {params: {number: 1}})
.then(function Succes(response) {$scope.person = response.data.people;});};
});
返回三個對象。我看不出有什麼錯誤,在控制檯(狀態200)的控制檯和參數傳遞(它建立這個網址:http://urltowebsite.com/database.json?number=1)。
我在這裏錯過了什麼?
怎樣的角度知道它shouild在'number'屬性篩選? – devqon
據我所知它是服務器端任務沒有做角內或你可以分配返回的JSON的第一個元素像'$ scope.person = response.data.people [0]' –