Код моего компонента ниже
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 ниже
</p>
<pre><code>{ "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 serve
Я получаю следующие ошибки
src / app / like / like.component.ts (1,42): ошибка TS2300: повторяющийся идентификатор 'Input».src / app / like / like.component.ts (2,9): ошибка TS2300: дубликат идентификатора 'Input'.
i 「wdm」: не удалось скомпилировать.
Я перепробовал все комбинации в tsconfig.json, но, похоже, ничего не работает.Странно, но смена пробелов в файле like.component.ts, похоже, работает.