Reputation: 2488
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?
Upvotes: 1
Views: 9044
Reputation: 66921
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
Upvotes: 3