使用@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()产品:字符串"(无输入重命名).
[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错误.通常,当您使用Angular CLI生成项目时, no-input-rename
会设置为 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屋!