我的组件代码如下
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" ] }
然而,每当我这样做时
吴氏服务
我收到以下错误
src/app/like/like.component.ts(1,42):错误 TS2300:重复 标识符"输入"。src/app/like/like.component.ts(2,9): 错误 TS2300: 重复的标识符"输入"。
i 「wdm」:编译失败。
我在tsconfig.json中尝试了所有组合,但似乎没有任何效果。奇怪的是,只是更改 like.component.ts 文件中的空格似乎有效。
您要导入Input
两次,请删除第二次导入。