escope 밖에있는이 변수에 액세스하는 방법은 무엇입니까?왜 "total_clients"변수에 액세스 할 수 없습니까?
수출 클래스 ClientsComponent이하는 OnInit { 제목 구현 : 콘솔에 인쇄의 경우 this.total_clients
문자열 = "모든 클라이언트"
clients: Client[] = [];
response: any;
total_clients: number;
total_pages: number;
pages: any[] = [];
constructor(private _clientService: ClientService) {}
ngOnInit() {
this._clientService.getData()
.subscribe(
data => this.response = data,
err => console.error(err),
() => {
this.clients = this.response.data,
this.total_clients = this.response.total
}
);
console.log(this.total_clients); <- i can not access this
}
데이터가 반환되기 전에 콘솔 로그가 발생합니다. 구독 내 콜백 함수를 사용하여 논리를 트리거하고 그 이외의 것을 사용할 수 있습니다. – dylpickle
[비동기 호출의 응답을 어떻게 반환합니까?] (http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call)의 가능한 복제본 – JJJ
확인. 그러나 foreach에이 변수를 처리해야하지만이 작업을 수행 할 수 없습니다() => {}. 로드 후이 변수가 사용되는지 확인하는 방법은 무엇입니까? – user3050037