2016-10-03 84 views
0

我有一個路線網址,如:如何router.navigate到路由具有id佔位inmidst路線網址

/departments/:id/employees/assign' 

,當我瀏覽到上述網址:

this._router.navigate(['/departments/:id/employees/assign', id]); 

然後角始終將傳遞的ID附加到URL的末尾,但這不是我想要的。

當我嘗試這個

this._router.navigate(['/departments/:id/employees/assign', {id: id}]); 

我得到這個網址在瀏覽器:

http://localhost:4200/departments/%3Aid/employees/assign;id=1 

我想要的網址是在瀏覽器:/departments/1/employees/assign

我有什麼要更改?

+0

您是否嘗試過使用模板文字?像'[\'/ departments/$ {id}/employees/assign \']' –

+0

''''''''''''''''''請解決它!所以你將asp.net視爲黑暗時代;-) – Pascal

回答

3

使用模板文字,形成動態URL是這樣的:

[`/departments/${id}/employees/assign`] 
0

如果你想使用一個鏈接,然後: 在HTML有:

<button type="button" id="btnOpenLine" class="btn btn-default btn-sm" ng-click="orderMaster.openLineItems()">Order Line Items</button> 
了打字稿文件

public openLineItems() { 
    if (this.$stateParams.id == 0) { 
     this.Flash.create('warning', "Need to save order!", 3000); 
     return 
    } 
    this.$window.open('#/orderLineitems/' + this.$stateParams.id); 
} 

我希望你看到這個前這對我和其他答案都是非常有幫助的。