2017-06-21 74 views
1

我試圖在成功刪除數據後重定向頁面。所以我把重定向router.navigate的訂閱數據部分。但它不工作,我也曾嘗試與ngZone也沒有任何反應。我也想展示成功的訊息。我怎樣才能表明這一點?router.navigate不起作用

沒有ngZone:

const rid = params['rid']; 
     this.roleSer.deleteRole(rid).subscribe(

      data => { this.router.navigate(['viewroles']) }, 
      error => { error } 
     ); 
    }); 

與ngZone:

const vrid = this.route.params.subscribe((params: Params) => { 
     const rid = params['rid']; 
     this.roleSer.deleteRole(rid).subscribe(
      data => { this.zone.run(()=>{ 
       this.router.navigate(['viewroles']) 
      }); }, 
      error => { error } 
     ); 
    }); 
+0

是什麼this.zone.run(() –

+0

感謝?對於你的建議我已經試過了但是不行 –

+0

你得到了什麼錯誤 –

回答

1

創建一個重定向功能,並用它

const vrid = this.route.params.subscribe((params: Params) => { 
      const rid = params['rid']; 
      this.roleSer.deleteRole(rid).subscribe(
       data => { 
        this.redirect('viewroles'); 
       }, 
       error => { error } 
      ); 
     }); 

    redirect(path): void { 
    this.router.navigate(['/' + path]) 
    } 
+1

沒有爲我工作(同一問題) –