使用 @Input() 时出现 TypeScript 错误 [英] TypeScript Error While Using @Input()
问题描述
我正在尝试使用 Angular 4 开发一个应用程序.但是我在使用
I am trying to develop an app using Angular 4. But I have received an error message while using
@Input('inputProducts') products: Product[];
错误是
[tslint] 在ProductListComponent"类中,指令输入属性产品"不应重命名.请考虑以下使用@Input() products: string"(无输入重命名).
[tslint] In the class "ProductListComponent", the directive input property "products" should not be renamed.Please, consider the following use "@Input() products: string" (no-input-rename).
错误没有任何影响,我的应用程序运行良好,但很烦人,无法将其删除.代码片段如下:
The Error Does Not Have any Effect and My App is working fine but it is annoying and am unable to remove it. Code Snippet is Given Below:
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Product } from '../product-row/product.model';
@Component({
selector: 'app-product-list',
templateUrl: './product-list.component.html',
styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {
@Input('inputProducts') products: Product[];
@Output() selectedProduct: EventEmitter<Product>;
constructor() {
this.selectedProduct = new EventEmitter();
}
clickedProduct(p: Product): boolean {
this.selectedProduct.emit(p);
return false;
}
ngOnInit() {
}
}
html 部分
<app-product-list [inputProducts]="products"></app-product-list>
请指出正确的方向以消除此错误.
Please Point me towards right direction to remove this error.
推荐答案
这是样式指南,no-input-rename
规则,您应该将其设置为 false 以免出现此类 tslint 错误.no-input-rename
通常在您使用 Angular CLI 生成项目时设置为 true
.转到您的 tslint 文件并使其值等于 false
.应该类似于:"no-input-rename": false
.
It's styleguide, no-input-rename
the rule that you should set to false not to get such tslint error. no-input-rename
is set to true
usually when you generate your project with Angular CLI. Go to your tslint file and make it's value equal to false
. Should look something like: "no-input-rename": false
.
这篇关于使用 @Input() 时出现 TypeScript 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!