Autoscroll in Angular 2

后端 未结 10 1181
清歌不尽
清歌不尽 2020-12-01 12:21

I\'m experiencing an issue with Angular 2 where changing from one route to another does not automatically scroll to the top of the new view. I realize that Angular 1 allowed

10条回答
  •  北海茫月
    2020-12-01 12:46

    Newer RCs (>= RC.3) don't seem to expose a changes Observable, it probably has since been renamed to events or routerEvents.

    Their utterly "fantastic" docs don't seem to provide any information on what's doing what, so I guess you're in for a little Russian Roulette there. Or flip a coin or something.

    From this answer, it seems the events Observable returns events regarding navigation state:

    router.events.subscribe(event:Event => {
        if(event is NavigationStart) {
        }
        // NavigationEnd
        // NavigationCancel
        // NavigationError
        // RoutesRecognized   
      }
    

提交回复
热议问题