Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular – “ActivatedRoute”类型中不存在属性“导航”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正试图通过配置文件组件(前一个组件)导航到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(...

大佬总结

以上是大佬教程为你收集整理的angular – “ActivatedRoute”类型中不存在属性“导航”全部内容,希望文章能够帮你解决angular – “ActivatedRoute”类型中不存在属性“导航”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: