【问题标题】:Angular 2 rc1 TypeError: Cannot read property 'annotations' of undefinedAngular 2 rc1 TypeError:无法读取未定义的属性“注释”
【发布时间】:2016-10-19 03:46:01
【问题描述】:

当我将应用程序更新到 rc1 时,我收到 TypeError: Cannot read property 'annotations' of undefined error。知道什么会导致这个问题吗? 我应该使用而不是 '@angular/router-deprecated' ,'@angular/router' 吗?

 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

【问题讨论】:

  • 您的&lt;body&gt; 元素是否包含&lt;account-app&gt;&lt;/account-app&gt; 标签?
  • 你能告诉我们完整的错误信息吗?
  • 是的,它包含......

标签: typescript angular angular2-routing


【解决方案1】:

我收到了同样的错误信息。这是因为我尝试使用 rc.4 运行大多数包(common、core 等),但路由器仍然位于 rc.1(发布时的最新版本)。将其他包移回 rc.1 解决了这个问题。

【讨论】:

    【解决方案2】:

    它看起来像角度错误/版本不兼容。尝试运行 npm install,检查 systemjs 配置,package.json,交换路由器版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-04
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多