我正在使用带有TypeScript的angular 6,并尝试使用导航从组件路由(RegisterComponent)导航到另一个组件路由(ProfileComponent)(使用routerLink也不起作用)。我尝试了许多发现的示例,但始终遇到相同的错误:
错误错误:未捕获(承诺):TypeError:无法读取未定义的属性>'removeEventListener' TypeError:无法读取未定义的属性'removeEventListener'
我的代码:
app.module.ts
import { RouterModule, Routes } from '@angular/router';
//hidden imports ...
export const appRoutes: Routes = [
{path: '', component: RegisterComponent},
{path: 'profile', component: ProfileComponent},
]
@NgModule({
declarations: [
AppComponent,
RegisterComponent,
ProfileComponent,
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
FormsModule,
ReactiveFormsModule,
CustomFormsModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [AppComponent],
exports: [ RouterModule]
})
export class AppModule { }
app.component.html
<router-outlet></router-outlet>
register.component.ts
import { Router, ActivatedRoute } from '@angular/router';
export class RegisterComponent {
constructor(private router: Router, private route: ActivatedRoute) { }
test(){
this.router.navigate(["../profile"], {relativeTo: this.route});
//this.router.navigate(["/profile"], {relativeTo: this.route});
}
}
register.component.html
<div (click)="test()">click</div>