0
안녕 얘들 아 어떻게 두 가지 방법에서 전역 범위 (this)에서 변수에 액세스 궁금하네요. 도움을 주신메서드 내에서 전역 변수에 액세스 Typescript
location: any;
doSomethingOne() {
Geolocation.getCurrentPosition().then((resp) => {
this.location = resp;
this.doSomething();
}).catch((error) => {
console.log('Error getting location', error);
});
}
doSomething() {
return new Promise(resolve => {
this.http.get('http://xxxxxxxxx.xxxx/api/' + this.location.coords.latitude + '/' + this.location.coords.longitude + '/5')
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
}
어떻게 Promise 내에서 this.location에 액세스 할 수 있습니까? 이
는'this' 글로벌 스코프없는 시도에 액세스 할 때 콘솔은 '정의되지 않은'보여줍니다. '창'입니다. * object * scope를 얻으려고한다면 arrow 함수는'then' 콜백 함수로 처리해야합니다. – estus