加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – “ActivatedRoute”类型中不存在属性“导航”

发布时间:2020-12-17 17:52:05 所属栏目:安全 来源:网络整理
导读:我正试图通过配置文件组件(前一个组件)导航到listProfiles组件.我正在使用ActivatedRoute并试图通过this.router.navigate([‘/ listProfiles])导航到它 组件中应该导航到listProfile组件的代码 import {ActivatedRoute,Router} from '@angular/router';const
我正试图通过配置文件组件(前一个组件)导航到listProfiles组件.我正在使用ActivatedRoute并试图通过this.router.navigate([‘/ listProfiles])导航到它

组件中应该导航到listProfile组件的代码

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]
})

解决方法

你必须添加:

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

然后 :

this.router.navigate(...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读