【问题标题】:Angular 2 Component name duplicatedAngular 2组件名称重复
【发布时间】:2017-04-04 07:56:24
【问题描述】:

Angular 2 的新手。创建应用程序,组件放置在相关文件夹中,如附图所示。结构如下:

- app
--components
---users
----create
----edit
---collaborations
----create
----edit

构建时(ng serve)错误:[默认]中的错误

...\src\app\app.module.ts:9:9    Duplicate identifier 'CreateComponent'.  

我该如何解决这个问题?

【问题讨论】:

    标签: angular angular2-directives


    【解决方案1】:

    您正在尝试导入CreateComponent 两次。当您导入时,您实际上是在添加类!因此,进入其中一个组件文件并重命名组件类。然后在必填字段中进行更改。

    第一个组件

    export class FirstComponent implements OnInit {
    
        constructor( private router: Router) { }
    
        ngOnInit() { }
    }
    

    第二个组件

    export class SecondComponent implements OnInit {
    
        constructor( private router: Router) { }
    
        ngOnInit() { }
    }
    

    现在导入它们,

    import { FirstComponent }                          from "./first-component";
    import { SecondComponent }                          from "./second-component";
    

    您还在声明中多次调用它。你需要给每个人打电话一次。确保以不同的方式命名它们,然后将每一个添加到声明中。

    【讨论】:

    • 看起来像是重命名,或者创建不同名称的组件。有没有其他办法解决?
    猜你喜欢
    • 2016-11-19
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 2017-04-12
    • 1970-01-01
    • 2017-05-20
    相关资源
    最近更新 更多