无法阅读属性'注释'使用routeconfig时未定义的

时间:2016-06-18 16:47:55

标签: javascript angular2-routing angular2-meteor

我正在使用社交应用教程来学习Angular2Meteor。我遇到了一个我无法找到根本原因的问题。

我跟随tutorial说明要添加:

RouteConfig注释:

@RouteConfig([
  { 
    path: '/', 
    as: 'PartiesList', 
    component: PartiesList 
  }, { 
    path: '/party/:partyId', 
    as: 'PartyDetails', 
    component: PartyDetails 
  }
]);
app.html中的

router-outlet

<router-outlet></router-outlet>

在Chrome中加载应用时出现此异常:

EXCEPTION: Error in /client/app.html:0:0BrowserDomAdapter.logError @ 
modules.js?hash=12bd683…:59337BrowserDomAdapter.logGroup @ modules.js?
hash=12bd683…:59347ExceptionHandler.call @ modules.js?
hash=12bd683…:48750(anonymous function) @ modules.js?
hash=12bd683…:54194ZoneDelegate.invoke @ modules.js?
hash=12bd683…:107413onInvoke @ modules.js?
hash=12bd683…:54615ZoneDelegate.invoke @ modules.js?
hash=12bd683…:107412Zone.run @ modules.js?
hash=12bd683…:107306NgZoneImpl.runInner @ modules.js?
hash=12bd683…:54646NgZone.run @ modules.js?
hash=12bd683…:54538ApplicationRef_.run @ modules.js?
hash=12bd683…:54183ApplicationRef_.bootstrap @ modules.js?
hash=12bd683…:54205(anonymous function) @ modules.js?
hash=12bd683…:53993(anonymous function) @ meteor.js?
hash=ae8b8af…:1105ZoneDelegate.invoke @ modules.js?
hash=12bd683…:107413onInvoke @ modules.js?
hash=12bd683…:54615ZoneDelegate.invoke @ modules.js?
hash=12bd683…:107412Zone.run 

...

modules.js?hash=12bd683…:59337 TypeError: Cannot read property 'annotations' 
of undefined
at RouteRegistry.configFromComponent (modules.js?hash=12bd683…:87825)
at new RootRouter (modules.js?hash=12bd683…:87151)
at routerFactory (modules.js?hash=12bd683…:89570)
at ReflectiveInjector_._instantiate (modules.js?hash=12bd683…:50544)
at ReflectiveInjector_._instantiateProvider (modules.js?hash=12bd683…:50473)
at ReflectiveInjector_._new (modules.js?hash=12bd683…:50462)
at ReflectiveInjectorDynamicStrategy.getObjByKeyId (modules.js?hash=12bd683…:50117)
at ReflectiveInjector_._getByKeyDefault (modules.js?hash=12bd683…:50642)
at ReflectiveInjector_._getByKey (modules.js?hash=12bd683…:50614)
at ReflectiveInjector_.get (modules.js?hash=12bd683…:50423)

如果我删除@RouteConfig,则不会发生任何异常,但显然没有任何内容显示,因为没有内容可供呈现。知道是什么导致了这个吗?

2 个答案:

答案 0 :(得分:0)

@RouterConfig仅适用于以前版本的路由器弃用和rc1。 随着新版本3.0.0.apha.7,它不再可用。请阅读Routing & Navigation

上的文档

示例用法是

export const DashboarRoutes = [
  {
    path: 'dashboard',
    component: DashboardComponent
  },
  ...
  e.t.c      
] 
export const routes: RouterConfig = [
...DashboardRoutes,
...UIRoutes
];

export const APP_ROUTER_PROVIDERS = [
   provideRouter(routes)
];


APP_ROUTER_PROVIDERS is then passed when bootstrapping main application

答案 1 :(得分:0)

经过一段时间后,角度和流星时间推出了新版本,在撰写本文时开箱即用。我偶然也想出了如何安装包。您可以使用以下格式:

meteor npm install @angular/core

例如安装angular core package