我想在另一個服務中使用ActivatedRoute服務。但是,在我的服務中,ActivatedRoute服務正在監視主應用程序組件,並且沒有任何路由參數變化正在從observable發出。如果我在同一個模塊的組件中觀察路由參數,則ActivatedRoute服務按預期運行。在另一個服務中使用ActivatedRoute
這裏是我的目錄的簡化版本,它
app/
├──app.module.ts <- RouterModule Imported Here
├──app.component.ts
|
└──other-module/
├──other.module.ts <- other.service provided here
├──other.component.ts <- ActivatedRoute works as expected
└──other.service.ts <- ActivatedRoute watches App component
這裏是我的路線配置的簡化版本:
export const routes: Routes = [
{ path: '', component: App },
{ path: 'other/:id', component: Other }
];
誰能提供了一些與如何正確處理和注入服務,以便我可以使用另一項服務中的ActivatedRoute服務。
謝謝。
我有同樣的問題 – piernik