简体   繁体   English

Angular 2编译失败

[英]Angular 2 Failed to compile

i created a new component in angular 2 with this: 我用这个在角度2中创建了一个新组件:

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 todos.component.css,todos.component.html,todos.component.spec.ts,todos.component.ts

Then I openened todos.component.ts and it had: 然后我打开todos.component.ts,它有:

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. C:/angular2/proyecto/src/app/todos/todos.component.ts(2,10):合并声明“ TodosComponent”中的各个声明必须全部导出或全部本地导出。

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. 无需导入自己的组件,应在使用它的其他文件中导入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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