Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'navigate' does not exist on type 'ActivatedRoute'

I'm trying to navigate to listProfiles component through profile component (The previous component). I'm using an ActivatedRoute and trying to navigate to it through this.router.navigate(['/listProfiles])

Code in the component that should navigate to listProfile component

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]
})
like image 730
Fig Avatar asked Oct 25 '17 09:10

Fig


People also ask

What does the ActivatedRoute interface allow you to access?

ActivatedRoutelink. Provides access to information about a route associated with a component that is loaded in an outlet.

What is ActivatedRoute?

The ActivatedRoute is the API that holds observable data that you can use to react to events with. You can subscribe to specific observable properties to get data from it asynchronously. The ActivatedRoute also contains ActivatedRouteSnapshot.


1 Answers

you have to add :

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

then :

 this.router.navigate(...
like image 128
Nawrez Avatar answered Oct 21 '22 04:10

Nawrez