0
我是AngularJS的新手。我從SQL獲取數據到AngularJS。我能夠以ng-repeat的形式顯示數據,但我想從我的控制器中的數據庫中傳遞的數組的某個屬性的值用於其他函數中。如何在AngularJS中獲取數組屬性的值
下面是我得到數據的控制器。 $ scope.candidates將候選對象的全部數據存儲在一個數組中。我只想得到名字。有沒有什麼像$ scope.candidates.Firstname?
app.controller('CandidateCtrl', ['$scope', 'CandidateService',
// we inject CandidatetService inject becuse we call getAll method for get all student
function ($scope, CandidateService) {
// this is base url
var baseUrl = '/api/Candidate/';
// get all candidate from databse
$scope.getCandidates = function() {
var apiRoute = baseUrl + 'GetCandidates/';
var _candidate = CandidateService.getAll(apiRoute);
_candidate.then(function (response) {
$scope.candidates = response.data;
},
function (error) {
console.log("Error: " + error);
});
}
$scope.getCandidates();
}]);
您已經提取了整個數據,只顯示名字。如果您想節省網絡流量,請僅從服務器發回。 –