2017-12-29 13 views
0

누구든지 내가 무엇을 놓치고 있는지 또는이 문제에 직면하고있는 실제 문제가 무엇인지 말해주십시오.동일한 컨트롤러에서 스코프에 액세스 할 수 없습니다. AngularJS

여기 내 컨트롤러입니다.

app.controller('UpdateLeadController', ['$scope', '$http', '$location', '$route', 'ProgramsFactory', 'CommonFactory', '$filter', 'ProcessFactory', 'Upload', '$routeParams', function($scope, $http, $location, $route, ProgramsFactory, CommonFactory, $filter, ProcessFactory, Upload, $routeParams) { 
$scope.limit = 3; 
$scope.loadMore = function() { 
    $scope.limit += 2; 
} 
$scope.programIs = 1; 

ProgramsFactory.Getprogramslist(1).then(function(response) { 
    $scope.programs = response.data.data; 
}); 
CommonFactory.Getclients().then(function(response) { 
    $scope.clients = response.data.data; 
}); 
ProgramsFactory.Getmonths().then(function(response) { 
    $scope.months = response.data.data; 
}); 

ProcessFactory.Getlead($routeParams.id).then(function(response){ 
    $scope.lead = response.data.data; // here i've got the lead data from factory. 
}); 
console.log($scope); // when i am printing this scope i am getting the object lead with all data. 
console.log($scope.lead); // when i am trying to print this. it outputs as `Undefined`. 
}]); 

이 문제는 계속되었습니다. 모든 데이터는 HTML에서 액세스 할 수 있지만 지시문뿐만 아니라 컨트롤러에서도 가져올 수 없습니다. 지시문은 데이터를 정의되지 않은 것으로 제공합니다.

while printing scope i can see the object. but when i am trying to access that object it showing it's undefined.

답변

0

의이 유

*이

$scope.limit = 3; 
$scope.loadMore = function() { 
    $scope.limit += 2; 
} 
$scope.programIs = 1; 
* $scope.programs$scope.clients$scope.months가 정의되지 않은 점에 유의 3 속성과 범위를 만든 최초의

작동하는 자바 스크립트 방법을 보자

다음 u cal 공장에서 그 방법은 데이터를 가져올 리터, 이러한 데이터를 가져 오는 동안, 다음과 같은 코드가

console.log($scope);// u got an object 
console.log($scope.lead); // u got an undefined, of course u never set it 

실행되는 몇 초 후에, 당신의 요구 중 하나의 예를 들어 Getlead 보자 을 완료하고, 이제 다음 코드는

$scope.lead = response.data.data; 

실행이 유 얻는 시간이다 $scope.lead

그런데 왜

console.log($scope) 

은 데이터를 가져온 후 모든 것을 보여줍니다.

콘솔에 '정보'아이콘이 있습니까? 어떤 the value is evaluated now... 또는 그런 말합니다. 즉, 처음에 로그 할 때 $scope 일 때 lead 속성이 없지만 가져 오기 프로세스가 끝나고 로그 데이터를 클릭하고 확장하면 reevaluate$scope.lead 속성을 참조하십시오. .

+0

시도했습니다. 여전히 같은 문제가 발생합니다. :( –

+0

데이터 소스와 관련하여 문제가 없습니다. 공장 호출로 모든 데이터를 가져 왔지만 액세스 할 수 없습니다. –