gpt4 book ai didi

javascript - Angular 2 Child Routing (v3) 'Cannot read property ' 注释' of undefined'

转载 作者:太空狗 更新时间:2023-10-29 17:57:50 26 4
gpt4 key购买 nike

我正在尝试使用 Angular 2 并运行一个测试应用程序,但我在让路由在最新版本的路由器 (3.0.0 alpha-7) 中工作时遇到了一些问题。

主要.ts:

import {bootstrap}    from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import {APP_ROUTER_PROVIDERS} from './app.routes';

bootstrap(AppComponent, [APP_ROUTER_PROVIDERS]);

应用程序组件.ts:

import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';

@Component({
selector: 'my-app',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent { }

app.routes.ts:

import {provideRouter, RouterConfig} from '@angular/router';
import {SigninRoutes} from './signin/signin.routes';

export const AppRoutes: RouterConfig = [
...SigninRoutes
]

export const APP_ROUTER_PROVIDERS = [
provideRouter(AppRoutes)
];

signin.component.ts:

import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';

@Component({
selector: 'signin',
template: `
<a [routerLink]="['/signin']">Sign In</a>
<a [routerLink]="['/profile']">Profile</a>
<br><br>Sign In Test
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})

export class SigninComponent {

}

signin.routes.ts:

import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';

@Component({
selector: 'signin',
template: `
<a [routerLink]="['/signin']">Sign In</a>
<a [routerLink]="['/profile']">Profile</a>
<br><br>Sign In Test
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})

export class SigninComponent {

}

配置文件.component.ts:

import {Component} from '@angular/core';

@Component ({
selector: 'profile',
template: `
Profile Test
`

})

export class ProfileComponent {

}

出于某种原因,我可以正常启动应用程序,但尝试单击 Profile routerLink 会导致错误:

“异常:错误:未捕获( promise ):类型错误:无法读取未定义的属性‘注释’”

如果有人能帮我解决这个问题,我将不胜感激。

最佳答案

听起来像:

类似问题:

检查常见错误:

  • 确保您的路线的路径中没有/
  • 确保每个路由都有componentredirectTochildren
  • 确保路由中使用的组件正确导入到定义路由的文件中

关于javascript - Angular 2 Child Routing (v3) 'Cannot read property ' 注释' of undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38065325/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com