2017-10-25 38 views
1

プロファイルコンポーネント(前のコンポーネント)を介してlistProfilesコンポーネントに移動しようとしています。私はActivatedRouteを使用してlistProfileコンポーネントに移動しなければならないコンポーネントにthis.router.navigate(['/listProfiles])プロパティ 'navigate'がタイプ 'ActivatedRoute'に存在しません

コードを通してそれにナビゲート

import {ActivatedRoute, Router} from '@angular/router'; 

constructor(private router: ActivatedRoute){} 

deleteProfile():void{ 
    this.router.navigate(['/listProfiles']); //Gives the error message in the title 
} 

app.module.tsしようとしている

import { ListProfilesComponent } from './list-profiles/list-profiles.component'; 
import { ProfileComponent } from './profile/profile.component'; 

const appRoutes: Routes = [ 
{ path: 'addProfile', component: AddProfileComponent }, 
{ path: 'listProfiles', component: ListProfilesComponent}, 
{ path: 'profile/:id', component: ProfileComponent}, 
{ path: 'login', component: LoginComponent} 
]; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    ListProfilesComponent, 
    ProfileComponent, 
    ], 
    imports: [ 
    FormsModule, 
    ReactiveFormsModule, 
    NoopAnimationsModule, 
    BrowserModule, 
    HttpModule, 
    RouterModule.forRoot(
    appRoutes, 
    {enableTracing: true} 
    ) 
    ], 
    providers: [ StorageService, LoginService, ClientIDService], 
    bootstrap: [AppComponent] 
}) 
+0

エラーは正しいです、あなたは 'ActivatedRoute'の代わりに' Router'を使うべきです – Alex

+0

そうです、それです!単純な間違いで申し訳ありません – Fig

+0

私たちすべてに起こる;) – Alex

答えて

3

あなたに追加する必要があります:

constructor(private route:ActivatedRoute,private router:Router) { } 

this.router.navigate(... 
+0

ああ、単純な間違いは、答えとして設定されます – Fig

+0

答えが正しい場合はなぜそれを提出しないでください??? – Nawrez

+1

投稿が15分間アップされていない限り、私はそれをすることができないからです。私が言ったように、私は数分で答えとしてそれを提出する – Fig

関連する問題