Angular2 RC3 +新组件未在路线上加载

时间:2016-09-18 06:49:21

标签: angular typescript

我需要帮助调试此问题。我差不多完成了我的项目。我们使用mgechev的angular2 / seed项目模板构建一个网站。我们正在使用RC3 angular2版本。我们的第一个版本不会更新到ng2。现在问题是两天前开始的,我必须再编写一个组件并通过路由加载它。

likes.Routes.ts

import { RouterConfig } from '@angular/router';

import { LikesComponent } from './index';

export const LikesRoutes: RouterConfig = [
  {
    path: 'likes',
    component: LikesComponent
  }
];

likes.component.ts

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

    @Component({
        moduleId: module.id,
        selector: 'sd-likes',
        templateUrl: 'likes.component.html',
        styleUrls: ['likes.component.css'],
        directives:[ROUTER_DIRECTIVES]
    })
    export class LikesComponent {
        constructor() {
            console.log('Likes component is loaded...');
        }
    }

app.routes.ts

import {
    provideRouter,
    RouterConfig
} from '@angular/router';

import {
    HomeRoutes
} from './+home/index';
import {
    UserProfileRoutes
} from './+profile/index';
import {
    LoginRoutes
} from './+login/index';
import {
    SignupRoutes
} from './+signup/index';
import {
    ConfirmPasswordRoutes
} from './+confirmPassword/index';
import {
    ProfileSettingRoutes
} from './+profileSetting/index';
import {
    EntitiesRoutes
} from './+entities/index';
import {LikesRoutes} from './+likes/index';

const routes: RouterConfig = [
    ...HomeRoutes,
    ...UserProfileRoutes,
    ...LoginRoutes,
    ...SignupRoutes,
    ...ConfirmPasswordRoutes,
    ...ProfileSettingRoutes,
    ...EntitiesRoutes,
    ...LikesRoutes
];

export const APP_ROUTER_PROVIDERS = [
    provideRouter(routes)
];

app.routes.ts文件中正确配置了路由。  问题是当我导航到likes网址时,我无法加载/likes组件。反讽是,我之前编写的所有组件都正在使用url正确加载。我在开发人员控制台和IDE控制台中都没有看到任何错误。我在chrome开发人员窗口上做了一些调试,我注意到我的LikesComponent类被调用(或加载),但是没有调用它的构造函数。当我以前编写的组件正确加载时,它会让我感到更烦恼,但不是这个,尽管它们没有太大区别。

请帮助我,我该怎么做才能解决这个问题。

**编辑:** 我最近将我的vsCode更新为最新版本(8月发布)。这是两者之间唯一的变化。

0 个答案:

没有答案
相关问题