I am trying to render a dynamic table with the ngFor directive. It's not rendering as desired.
This is my html:
- <form name="yourForm">
- <table>
- <tr *ngFor="let item of items">
- <td>{{item[1]}} td>
- <td>{{item[0]}} td>
- <td>{{item[2]}}td>
- tr>
- table>
- form>
This is in my controller:
- export class ShoppingCartComponent implements OnInit {
- items = [];
- onSubmit(quantity, product_name, product_price){
- localStorage.setItem('items', JSON.stringify(quantity, product_name, product_price));
- this.items.push( String(quantity), product_name, product_price );
- }
- }
It is rendered as follows:
- <table>
- <tr>
- <td>quantitytd>
- <td>td>
- <td>td>
- tr>
- <tr>
- <td>product_nametd>
- <td>td>
- <td>td>
- <tr>
- <td>product_pricetd>
- <td>td>
- <td>td>
- tr>
- tr>
- table>
My desired rendering is:
- <table>
- <tr>
- <td>quantitytd>
- <td>product_nametd>
- <td>product_pricetd>
- tr>
- table>
Maureen MoorePosted Jul 14, 2020, 1:15 PM
Laxmidhar SahooPosted Jul 13, 2020, 4:42 AM
Maureen MoorePosted Jul 12, 2020, 1:30 PM
Maureen MoorePosted Jul 12, 2020, 11:48 AM
Laxmidhar SahooPosted Jul 12, 2020, 4:46 AM
Rajanikant HawaldarPosted Jul 12, 2020, 2:33 AM