首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角2子路由(v3)‘无法读取未定义的属性’注释‘

角2子路由(v3)‘无法读取未定义的属性’注释‘
EN

Stack Overflow用户
提问于 2016-06-28 00:40:17
回答 2查看 2.8K关注 0票数 4

我试图在角2中运行测试应用程序,但在路由器的最新版本(3.0.0 alpha-7)中,我遇到了一些问题。

main.ts:

代码语言:javascript
复制
import {bootstrap}    from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import {APP_ROUTER_PROVIDERS} from './app.routes';

bootstrap(AppComponent, [APP_ROUTER_PROVIDERS]);

app.component.ts:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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 {

}

profile.component.ts:

代码语言:javascript
复制
import {Component} from '@angular/core';

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

})

export class ProfileComponent {

}

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

例外:错误:未知(承诺):TypeError:无法读取未定义的属性‘注释’

如果有人能帮我解决这个问题,我会很感激的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-28 06:00:54

听起来像是:

类似问题:

检查常见错误:

  • 确保在您的路线的/中没有path
  • 确保每条路线都有componentredirectTochildren
  • 确保正确地将路由中使用的组件导入到定义路由的文件中。
票数 1
EN

Stack Overflow用户

发布于 2016-09-25 02:14:30

我在使用webpack时出错,并试图异步加载如下所示的路由:

代码语言:javascript
复制
{
 path: 'password', loadChildren: () => new Promise(resolve => {
   (require as any).ensure([], require => {
     resolve(require('./password/password.module').PasswordModule);
   });
 })
},

上面的代码没有什么问题,但是看看我以为正在加载的模块:

代码语言:javascript
复制
@NgModule({
imports: [
 CommonModule,
 ...
],
declarations: [
  ...
],
providers: [
 ...
]
})
export class LockedModule {}  // wrong name !!!!

注意模块的名称,LockedModule,它应该是PasswordModule。我无意中发现了这个,我花了一段时间才找到。通常情况下,我滚动到底部并验证导出名称,而调试窗口没有给出原因的指示。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38065325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档