How to auto redirect after X seconds in AngularJS?

前端 未结 5 833
自闭症患者
自闭症患者 2021-01-17 22:24

What is the right way to do this in AngularJS? I didn\'t find any simple answer to this.

I\'d like to :

  1. Load a page
  2. Wait for X seconds
5条回答
  •  猫巷女王i
    2021-01-17 22:55

    If someone is looking for the same feature in angular 2 +.

    import { Router } from '@angular/router';
    
    constructor(private router: Router) {}
    
    ngOnInit() {
        // do init at here for current route.
    
        setTimeout(() => {
            this.router.navigate(['nextRoute']);
        }, 5000);  //5s
    }
    

提交回复
热议问题