Angular 2 rc1 TypeError: Cannot read property 'annotations' of undefined
Angular 2 rc1 TypeError: Cannot read property 'annotations' of undefined
我收到 TypeError: Cannot read 属性 'annotations' of undefined error 当我将我的应用程序更新到 rc1 时。知道什么会导致这个问题吗?
我应该使用而不是 '@angular/router-deprecated' ,'@angular/router' 吗?[=13=]
import {Component, provide, Optional, Inject, NgZone} from '@angular/core';
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {CliRouteConfig} from './route-config';
//import * as Redux from 'redux';
import {RegisterSimple} from './register-simple/register-simple';
import {Register} from './register/register';
@Component({
selector: 'account-app',
providers: [],
template: `
<h2>Account</h2>
<nav>
<a [routerLink]="['RegisterSimple']" class="nav-register-simple">Register Simple</a>
<a [routerLink]="['Register']" class="nav-register">Register</a>
</nav>
<hr>
<div style="margin:20px; border:1px solid #ccc;">
<router-outlet></router-outlet>
</div>
`,
directives: [ROUTER_DIRECTIVES, RegisterSimple],
pipes: []
})
@RouteConfig([
{ path: '/register-simple', name: 'RegisterSimple', component: RegisterSimple },
{ path: '/register', name: 'Register', component: Register },
].concat(CliRouteConfig))
export class AccountApp {
private userState: any = null;
constructor(
private ngZone: NgZone,
@Optional() @Inject('UserStore') UserStore: any
) {
let userData = {
general: {
userNodeID: 123,
username: 'Max.m',
firstname: 'Max',
lastname: 'Mustermann',
salutation: 'Mr',
birthdate: '23.12.1988'
},
address: {
street: 'Musterstraße',
houseNumber: '4',
postCode: '4020',
city: 'Linz',
countryCode: 'AT'
},
contact: {
phone: '0123456789',
email: 'max@mustermann.at',
newsletter: true
},
payment: {
accountHolderName: 'Max Mustermann',
bic: 'AT65232323',
iban: 'AT9837272727272'
},
culture: {
currency: 'EUR',
language: 'de',
oddFormat: 'Decimal'
}
}
this.ngZone.runOutsideAngular(() => {
this.ngZone.run(() => {
});
});
}
}
Main.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AccountApp, environment} from './app';
if (environment.production) {
enableProdMode();
}
bootstrap(AccountApp);
错误信息
EXCEPTION: Error in :0:0
browser_adapter.ts:78 EXCEPTION: Error in :0:0BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 ORIGINAL EXCEPTION: TypeError: Cannot read property 'annotations' of undefinedBrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 TypeError: Cannot read property 'annotations' of undefined
at RouteRegistry.configFromComponent (route_registry.ts:112)
at new RootRouter (router.ts:522)
at routerFactory (router_providers_common.ts:31)
at DebugAppView.get (AccountApp_Host.template.js:55)
at DebugAppView._View_AccountApp_Host0.injectorGetInternal (AccountApp_Host.template.js:95)
at DebugAppView.AppView.injectorGet (view.ts:145)
at DebugAppView.injectorGet (view.ts:325)
at ElementInjector.get (element_injector.ts:16)
at DebugAppView._View_AccountApp0.createInternal (AccountApp.template.js:60)
at DebugAppView.AppView.create (view.ts:110)BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 ERROR CONTEXT:BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 DebugContext
看起来 angular bug/version 不兼容。尝试 运行 npm 安装,检查 systemjs 配置,package.json,交换路由器版本。
我有同样的错误信息。这是因为我试图 运行 大多数包(通用、核心等)与 rc.4 和仍然有 rc.1 的路由器(发布时的最新版本)。将其他包移回 rc.1 解决了这个问题。
我收到 TypeError: Cannot read 属性 'annotations' of undefined error 当我将我的应用程序更新到 rc1 时。知道什么会导致这个问题吗? 我应该使用而不是 '@angular/router-deprecated' ,'@angular/router' 吗?[=13=]
import {Component, provide, Optional, Inject, NgZone} from '@angular/core';
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {CliRouteConfig} from './route-config';
//import * as Redux from 'redux';
import {RegisterSimple} from './register-simple/register-simple';
import {Register} from './register/register';
@Component({
selector: 'account-app',
providers: [],
template: `
<h2>Account</h2>
<nav>
<a [routerLink]="['RegisterSimple']" class="nav-register-simple">Register Simple</a>
<a [routerLink]="['Register']" class="nav-register">Register</a>
</nav>
<hr>
<div style="margin:20px; border:1px solid #ccc;">
<router-outlet></router-outlet>
</div>
`,
directives: [ROUTER_DIRECTIVES, RegisterSimple],
pipes: []
})
@RouteConfig([
{ path: '/register-simple', name: 'RegisterSimple', component: RegisterSimple },
{ path: '/register', name: 'Register', component: Register },
].concat(CliRouteConfig))
export class AccountApp {
private userState: any = null;
constructor(
private ngZone: NgZone,
@Optional() @Inject('UserStore') UserStore: any
) {
let userData = {
general: {
userNodeID: 123,
username: 'Max.m',
firstname: 'Max',
lastname: 'Mustermann',
salutation: 'Mr',
birthdate: '23.12.1988'
},
address: {
street: 'Musterstraße',
houseNumber: '4',
postCode: '4020',
city: 'Linz',
countryCode: 'AT'
},
contact: {
phone: '0123456789',
email: 'max@mustermann.at',
newsletter: true
},
payment: {
accountHolderName: 'Max Mustermann',
bic: 'AT65232323',
iban: 'AT9837272727272'
},
culture: {
currency: 'EUR',
language: 'de',
oddFormat: 'Decimal'
}
}
this.ngZone.runOutsideAngular(() => {
this.ngZone.run(() => {
});
});
}
}
Main.ts
import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AccountApp, environment} from './app';
if (environment.production) {
enableProdMode();
}
bootstrap(AccountApp);
错误信息
EXCEPTION: Error in :0:0
browser_adapter.ts:78 EXCEPTION: Error in :0:0BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 ORIGINAL EXCEPTION: TypeError: Cannot read property 'annotations' of undefinedBrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 TypeError: Cannot read property 'annotations' of undefined
at RouteRegistry.configFromComponent (route_registry.ts:112)
at new RootRouter (router.ts:522)
at routerFactory (router_providers_common.ts:31)
at DebugAppView.get (AccountApp_Host.template.js:55)
at DebugAppView._View_AccountApp_Host0.injectorGetInternal (AccountApp_Host.template.js:95)
at DebugAppView.AppView.injectorGet (view.ts:145)
at DebugAppView.injectorGet (view.ts:325)
at ElementInjector.get (element_injector.ts:16)
at DebugAppView._View_AccountApp0.createInternal (AccountApp.template.js:60)
at DebugAppView.AppView.create (view.ts:110)BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 ERROR CONTEXT:BrowserDomAdapter.logError @ browser_adapter.ts:78
browser_adapter.ts:78 DebugContext
看起来 angular bug/version 不兼容。尝试 运行 npm 安装,检查 systemjs 配置,package.json,交换路由器版本。
我有同样的错误信息。这是因为我试图 运行 大多数包(通用、核心等)与 rc.4 和仍然有 rc.1 的路由器(发布时的最新版本)。将其他包移回 rc.1 解决了这个问题。