1

I'm new in Angular2 and TypeScript. When I try some examples like this bellow

  @Component({
  selector: 'counter',
  template: `
    {{ value }}
    <button (click)="increase()">Increase</button>
    <button (click)="decrease()">Decrease</button>
  `
  })
  class Counter {
    value: number;

    constructor() {
    this.value = 1;
    }

    increase() {
    this.value = this.value + 1;
    }

    decrease() {
    this.value = this.value - 1;
    }
} 

I face "Cannot find name 'Component'" error on compile.

What's the problem? What should I do?

1
  • 3
    have you imported the Component decorator? Commented Jun 30, 2016 at 19:52

1 Answer 1

3

You need to import things in TS, It doesn't know what that decorator is otherwise, but within angular you can provide it.

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

Also make sure you export your class so you can import it elsewhere.

export class Counter 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.