Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript Error While Using @Input()

I am trying to develop an app using Angular 4. But I have received an error message while using

@Input('inputProducts') products: Product[];

The Error is

[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() {
  }
}

the html part

<app-product-list [inputProducts]="products"></app-product-list>

Please Point me towards right direction to remove this error.

like image 615
Moaz Sarwar Avatar asked Nov 04 '17 06:11

Moaz Sarwar


3 Answers

@Input() inputProducts: Product[]; should fix your problem.

like image 80
BogdanC Avatar answered Oct 27 '22 15:10

BogdanC


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.

like image 29
komron Avatar answered Oct 27 '22 14:10

komron


products: Product[];

@Input('inputProducts')
set productsFromInput(projects: Project[]) {
  this.products = products;
}
like image 28
Sygmoral Avatar answered Oct 27 '22 13:10

Sygmoral