在我的個人專案中,我遇到了一個錯誤。
基本上我想在edit-listing-component.html的輸入欄位中自動填充我擁有的當前資料。為了實作這一點,我創建了一個名為 Listing-data-form-component 的父組件,并帶有 @input 標簽
@Input() currentName = '';
@Input() currentDescription = '';
@Input() currentPrice = '';
這是鏈接
https://github.com/abhijitutkarsh/buyandsell/blob/last-update/src/app/listing-data-form/listing-data-form.component.ts
和編輯串列組件。 html 我叫它,這里的鏈接是代碼
https://github.com/abhijitutkarsh/buyandsell/blob/last-update/src/app/edit-listing-page/edit-listing-page.component.html
問題是,我的 currentName 和 currentDescription 作業得非常完美,因為它們是字串,所以資料正在自動填充
,currentPrice 因為它是數字而出現問題......我無法確定如何解決這個問題
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.
請幫助
uj5u.com熱心網友回復:
你試試這個方法。
@Input() currentPrice: number;
or
@Input() currentPrice = 0;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/485629.html
