【问题标题】:Maunal Navigation in Angular 6Angular 6 中的手动导航
【发布时间】:2019-10-11 13:04:32
【问题描述】:

如何根据某些功能的结果重定向到 Angular 6 中的其他组件?

    Login(){

        console.log(this.LoginModel);
         this.userService.LoginUser(this.LoginModel).subscribe(
           result =>{
             if(result == null)
                console.log("Loged in successfully"); 
                /// here i want to go to dashboard component (router with path dashboard)               
           },
           error =>{
             console.log("Login - error");
           }

         );
      }

【问题讨论】:

    标签: angular routing communication


    【解决方案1】:

    在您的构造函数中注入路由器服务。

    import {Router} from "@angular/router";
    
    constructor(
        private _router: Router
    ) {
    
    }
    
    goSomewhere() {
        this._router.navigate(['url']);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2021-10-06
      • 2017-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      相关资源
      最近更新 更多