본문 바로가기

프레임워크/Angular

angular window.scrollTo 안먹힐때

- 참고 https://zinee-world.tistory.com/543

 

 

1. 문제

- window.scrollTo 를 사용해야 함

- 그런데 angular 에서 window ~ documnet 를 콘솔창에 찍으면 ... 앵귤러쿤 ,,  정신차려

참고 (https://seo-developer.tistory.com/100)

 

 

 

2. 해결

     1). 이벤트가 발생한 html 태그에 함수 추가


<button  (click)="setScrollEvent(targetScroll)"> 테스트 버튼 </...

 

 

     2). 스크롤을 적용할 타겟 세팅


        <div class="wrap_sub-cont" #targetScroll >
          <router-outlet></router-outlet>
        </div>

 

     3). 함수 세팅

  setScrollEvent($element: any) {
     $element.scrollTo({
       top: 0,                     //최상단 높이값
       behavior: 'smooth'  //부드럽게 이동
     });
   }   

 

'프레임워크 > Angular' 카테고리의 다른 글

pipe, custom pipe 사용하기  (0) 2025.02.18
Angular 에서 QuerySelector 사용하기  (0) 2025.02.05
Angular 초기 설정  (0) 2024.11.06
angular 에서 JSON 형식 가시화  (0) 2024.10.10
standalone 관련  (1) 2024.09.26