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();
}]);
이미 전체 데이터를 가져 왔으며 이름 만 표시했습니다. 네트워크 트래픽을 줄이려면 서버에서 보낸 트래픽 만 보내십시오. –