저는 아약스 (get) 요청을하고 각도 "jobList"서비스에서 json 데이터를 사용하여 약속을 얻습니다.
그런 다음 획득 한 데이터로 범위를 업데이트합니다. 하지만 내 문제는 범위 변수 'X'를 업데이트하려면 변수 "readX"(벨로우 참고) 당 함수를 만들어야한다는 것입니다.
다음 코드의 마지막 함수와 같이 매개 변수를 추가하는 방법이 있습니까?
app.controller("JobListController", ['$scope', '$timeout', 'jobList',
function ($scope, $timeout, jobList) {
var readList = function (response) {
if (response) {
$timeout(function() {
$scope.list = response;
$scope.$apply();
});
}
};
var readFamilies = function (response) {
if (response) {
$timeout(function() {
$scope.allFamilies = response;
$scope.$apply();
});
}
};
var readRegions = function (response) {
if (response) {
$timeout(function() {
$scope.allRegions = response;
$scope.$apply();
});
}
};
// !!! ----- HERE ------------- !!!
var readSomething = function (response, something) {
if (response) {
$timeout(function() {
$scope[something] = response;
$scope.$apply();
});
}
};
jobList.get().then(readList);
jobList.getAll("allFamilies").then(readFamilies);
jobList.getAll("allRegions").then(readRegions);
}]);
이 전화 foreach는 기능을 할 필요가, 다음 변수를 설정합니다
당신이 정말로 (그들은 여전히 병렬로 평가)는 콜백을 생성하는 공장을 작성할 수 있습니다 개별적으로 전화를 확인하려면
함수를 호출하십시오 ... – Serge예, 그렇지 않으면 닫는 방법을 살펴볼 수 있습니다, 나는 내 대답을 편집했습니다 – gaurav5430
어떻게 readSomething을 사용할 수 있습니까? – Serge