Click here to Skip to main content
15,887,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
//----------Model.ts=============
Angular
export interface Product {
    id: number;
    name: string;
    description: string;
    scale: string;
    price: number;
    variants: ProductVariant[];
}

export interface ProductVariant {
    id: number;
    productId: number;`
    roastingTypeId: number;
    weightCoffee: string;
    priceCoffee: number;
    
  }
//=========component.ts==============
export class ProductDetailsComponent implements OnInit {
  private basketSource = new BehaviorSubject<Basket | null>(null);

  products: Product;
 constructor(private shopService: ShopService, private activatedRoute: ActivatedRoute) { 
      this.bcService.set('@productDetails', '');
  }

ngOnInit(): void {
   this.loadProduct();
   //this.getRoastingOption();
   this.getRoast();
   this.getWeight();
   this.getproductTest();
  }
  loadProduct() {
    const id = this.activatedRoute.snapshot.paramMap.get('id');
    if (id) this.shopService.getProduct(+id).subscribe({
      next: Product => {
        debugger;
        this.products = Product;
   }
//====================HTML=============================
select class="form-control" formControl="option.weightCoffee" id="weightCoffee" (change)="onRoastingoption($event.target.value)">
                      <option value="">please select roasting option ...</option>
                      <option *ngFor="let option of products.variants" [value]="option.value">{{ option.weightCoffee }}</option>
                    </select>


What I have tried:

Please check the issue. It is not displayed on the HTML page. Thanks!
Posted
Updated 13-Sep-23 3:49am
v3

As you are subscribing to the service, I have to assume that the load is being triggered from there. Have a look in the network tab in your browser and see if any data comes back from the call. As you are using next, I would suggest that you should also look at adding error handling into your subscription to see if you are encountering a problem.
 
Share this answer
 
It looks like you're trying to bind the value of 'option.weightCoffee' to the 'select' element using 'formControl', the correct syntax for binding a form control to a select element is using the [formControl] directive. Your code should be -
Angular
<select class="form-control" [formControl]="selectedRoastingOption" id="weightCoffee" (change)="onRoastingoption($event.target.value)">
  <option value="">please select roasting option ...</option>
  <option *ngFor="let option of products.variants" [value]="option.weightCoffee">{{ option.weightCoffee }}</option>
</select>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900