Mark Rajcok
Mark Rajcok

Reputation: 364677

Angular 2 Exception: TypeError: Cannot read property 'annotations' of undefined

What am I doing wrong?

app.component.ts

import {Component} from 'angular2/core';
@Component({
  selector: 'my-app',
  template: `{{title}}`
})
export class App {
  title = "Angular 2 beta";
  constructor() { console.clear(); }
}

main.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';

bootstrap(AppComponent);

The error is

EXCEPTION: TypeError: Cannot read property 'annotations' of undefined

Upvotes: 12

Views: 10031

Answers (1)

Mark Rajcok
Mark Rajcok

Reputation: 364677

The class name doesn't match what you are bootstrapping. I.e., instead of

export class App { ... }

use

export class AppComponent { ... }

Angular is trying to find the annotations property of a class named AppComponent, but that class doesn't exist, hence the error.

Upvotes: 21

Related Questions