Jesús Cova
Jesús Cova

Reputation: 339

Angular 2 Failed to compile

i created a new component in angular 2 with this:

ng g component todos

So it created the new component, I went to the component and I noted that I had a new folder with the files:

todos.component.css, todos.component.html, todos.component.spec.ts, todos.component.ts

Then I openened todos.component.ts and it had:

import { Component, OnInit } from '@angular/core';
@Component({
   selector: 'app-todos',
   templateUrl: './todos.component.html',
   styleUrls: ['./todos.component.css']
})

export class TodosComponent implements OnInit {
   constructor() { }
   ngOnInit() {
   }
}

Then I put the new second line because I am learning with a tutorial:

import { Component, OnInit } from '@angular/core';
import { TodosComponent } from './todos/todos.component';

@Component({
   selector: 'app-todos',
   templateUrl: './todos.component.html',
   styleUrls: ['./todos.component.css']
})

export class TodosComponent implements OnInit {
   constructor() { }
   ngOnInit() {
   }
}

When I did that and I ran the server it showed me this:

Failed to compile.

C:/angular2/proyecto/src/app/todos/todos.component.ts (2,10): Individual declarations in merged declaration 'TodosComponent' must be all exported or all local.

I'd like to know what is it bad? why does it show that error?

Thanks!

Upvotes: 0

Views: 110

Answers (1)

eavichay
eavichay

Reputation: 517

You are importing the class into it's own file.

No need to import your own component, you should import it in other files, where you use it.

Upvotes: 1

Related Questions