Hi Maureen, I do not see where you set the product_price variable. Did you forget to initialize it's value?
-Luke On Fri, Jul 17, 2020 at 7:33 AM Maureen Moore <makam...@gmail.com> wrote: > When I get the product_price it returns "Unsupported value type" as a > result of the function below but I need for it to be a number. I tried > this.product_price = parseFloat(this.product_price); but that returns the > error: Argument of type 'number' is not assignable to parameter of type > 'string'. How do I cast product_price as a number? > > In my HTML: > > <div>{{ totalPrice }}</div> > <ul *ngFor="let product of products"> > <li> > <div>{{product.price }}</div> > <button type="submit" class="btnAddAction" (click)="onSubmit( > [product.price] )">Add to Cart</button> > </li> > </ul> > > > > The HTML is getting the products from the database which was created with > this JSON: > > { > "products": [ > { > "price": 20.50, > }, > { > "price": 20.50, > }, > { > "price": 12.75, > } > ] > } > > > > > > In my controller typescript file: > > get totalPrice() { > if (typeof this.product_price === "string") { > return "string"; > } > if (typeof this.product_price === "number") { > return "number"; > } else { > throw Error("Unsupported value type") > } > } > product_price: number; > > > onSubmit(product_price){ > product_price = parseFloat(product_price); > const data = { > product_price > }; > this.items.push(data); > localStorage.setItem('items', JSON.stringify(this.items)); > } > > > > -- > You received this message because you are subscribed to the Google Groups > "Angular and AngularJS discussion" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to angular+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/angular/86dbd802-60fb-45d1-8450-1a8fcc744360o%40googlegroups.com > <https://groups.google.com/d/msgid/angular/86dbd802-60fb-45d1-8450-1a8fcc744360o%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Lucas Lacroix Computer Scientist RESTful APIs & Cloud Platform Advanced Technology Division, MEDITECH <http://ehr.meditech.com> 781-774-2293 -- <https://ehr.meditech.com/expanse> <https://www.linkedin.com/company/meditech> <https://twitter.com/MEDITECH> <https://www.facebook.com/MeditechEHR> Subscribe <https://info.meditech.com/get-great-meditech-content?hsCtaTracking=864299ec-5abf-4004-9c6d-2d051794101f%7Cc911be42-538a-4a48-8dca-a6d4001c6326> to receive emails from MEDITECH or to change email preferences. COVID-19 Customer Resources <https://customer.meditech.com/en/d/covid19resources/homepage.htm> -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/CAEV-7cS%2Bzv0EMh7WGv9o6J%2BoyYStFB0RDMU%3DA8n5MxWVPnm6sg%40mail.gmail.com.