角度-重复的标识符“输入”

时间:2018-12-23 04:49:44

标签: angular typescript angular7 tsconfig

我的组件代码在

之下

import {Component, EventEmitter, OnInit, Input, Output} from '@angular/core';
import {Input} from '@angular/compiler/src/core';

@Component({
    selector: 'like',
    templateUrl: './like.component.html',
    styleUrls: ['./like.component.css']
})
export class LikeComponent implements OnInit {
    @Input('isActive') isSelected: boolean;
    @Input('likesCount') likesCount: number;
    @Output('change') click = new EventEmitter();


    constructor() {}
    ngOnInit() {}

    isLiked() {}

    onClick() {
    //Ignore below incomplete code 
        if (!this.isSelected) {

        } else {

        }
        this.isSelected = !this.isSelected;
        this.click.emit({newValue: this.isSelected});
    }

    getStyle() {
        let style: string;
        if (this.isSelected) {
            style = 'deeppink';
        } else {
            style = '#ccc';
        }
        return style;
    }
}

export interface LikeChangedEventArgs {
    newValue: boolean;
}
.glyphicon-heart{
    font-size: 50px;
    color: #cccccc;
    cursor: pointer;
}
<span class="glyphicon glyphicon-heart"
      (click)="onClick()" [style.color]="getStyle()">
</span>
<span style="font-size: 50px;">{{likesCount}}</span>

我的tsconfig.json在下面

{   "compileOnSave": false,   "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]   },   "exclude": [
    "bower_components/**",
    "node_modules/**",
    "typings/main.d.ts",
    "typings/main/**",
    "typings/index.d.ts"   ] }

但是,只要我做

  

ng服务

我收到以下错误

  

src / app / like / like.component.ts(1,42):错误TS2300:重复   标识符“输入”。 src / app / like / like.component.ts(2,9):错误TS2300:   重复的标识符“输入”。

     

我「wdm」:编译失败。

我尝试了tsconfig.json中的所有组合,但似乎无济于事。奇怪的是,仅更改like.component.ts文件中的空格似乎可行。

1 个答案:

答案 0 :(得分:4)

您要两次导入Input,请删除第二次导入。