简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM