Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Angular Router
- 스크롤 이벤트 감지
- TAILWIND
- egov spring ajax 사용 예시
- 검색
- 앵귤러 모달
- formgroup
- 스크롤 이벤트
- mysql if
- angular route
- ajax 사용 예시
- Router
- modal
- flex-1
- summary
- 셀렉트박스 커스텀
- 옵저버블
- angular button
- scroll
- 호버
- prisma
- 앵귤러 애니메이션
- angular animation
- Oracle LISTAGG 사용 예시
- route
- angular modal
- ApexChart
- 아이오닉 스크롤 이벤트
- 모달
- Ionic modal
Archives
- Today
- Total
깜놀하는 해므찌로
@Observable @subscribe() 본문
반응형
SMALL
// 구독자가 구독을 실행하면 새로운 Observable 인스턴스를 생성하고
// 클라이언트의 접속 위치를 추적하기 시작합니다.
const locations = new Observable((observer) => {
let watchId: number;
// 접속 위치를 처리하는 API는 간단하게 사용해 봅니다.
if ('geolocation' in navigator) {
watchId = navigator.geolocation.watchPosition((position: GeolocationPosition) => {
observer.next(position);
}, (error: GeolocationPositionError) => {
observer.error(error);
});
} else {
observer.error('Geolocation not available');
}
// 구독자가 구독을 해지하면 사용하던 데이터를 모두 지웁니다.
return {
unsubscribe() {
navigator.geolocation.clearWatch(watchId);
}
};
});
// 옵저버블을 시작하려면 subscribe() 함수를 실행합니다.
const locationsSubscription = locations.subscribe({
next(position) {
console.log('Current Position: ', position);
},
error(msg) {
console.log('Error Getting Location: ', msg);
}
});
// 옵저버블은 10초 후에 구독을 해지합니다.
setTimeout(() => {
locationsSubscription.unsubscribe();
}, 10000);
반응형
LIST
'IT' 카테고리의 다른 글
Tailwind 단어 단위 줄바꿈 CSS (0) | 2023.05.24 |
---|---|
typescript readonly 활용 예시 (0) | 2023.05.24 |
typescript 접근제한자 (0) | 2023.05.23 |
Swiper too big size / Swiper size handle example / 스와이퍼 슬라이드 사이즈 조절 (0) | 2023.05.22 |
Angular External Url / 앵귤러 외부 url 요청 예시 / 앵귤러 새창열기 (0) | 2023.05.22 |