Home > Software engineering >  error TS2322: Type 'number' is not assignable to type 'string'. [currentPrice]=&
error TS2322: Type 'number' is not assignable to type 'string'. [currentPrice]=&

Time:06-04

In my personal project, i stuck with a error.

Basically I want to autofill the current data that i have, in the Input field in edit-listing-component.html. To achieve this i created a parent component named Listing-data-form-component, with @input tag made

@Input() currentName = '';
@Input() currentDescription = '';
@Input() currentPrice = '';

here is the link
https://github.com/abhijitutkarsh/buyandsell/blob/last-update/src/app/listing-data-form/listing-data-form.component.ts

and in the edit-listing-component.html i called it, link here is the code
https://github.com/abhijitutkarsh/buyandsell/blob/last-update/src/app/edit-listing-page/edit-listing-page.component.html

the matter is, my currentName and currentDesciption is working just perfectly that is data is getting autofilled since they are string
the issue is coming with the currentPrice since it is number....i am not able to identify how to resolve this

Error 
error TS2322: Type 'number' is not assignable to type 'string'.

7     [currentPrice]="listing.price"
       ~~~~~~~~~~~~

  src/app/edit-listing-page/edit-listing-page.component.ts:8:16
    8   templateUrl: './edit-listing-page.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component EditListingPageComponent.

Kindly help

CodePudding user response:

You try this way.

   @Input() currentPrice: number;
   or 
   @Input() currentPrice = 0;
  • Related