<select class="form-control" formControlName="recipe_ingredient">
<option value="">Select Ingredient</option>
<option *ngFor="let ingredient of ingredients | async" [value]="ingredient.id" [selected]="ingredient.id == ri.ingredient">
{{ingredient.id}}-{{ingredient.name}}
</option>
ri.ingredient = 2; But below does not return true in above code so value is not selected
ingredient.id == ri.ingredient
can any one please guide
The code in my ts file is as below:
editRecipeForm() {
this.editrecipeForm = this.fb.group({
recipe_name: ['', Validators.required ],
recipe_description: ['', Validators.required ],
edit_recipe_image: [],
ingredients11: this.fb.array([
this.getIngredient()
])
});
} 12:49
getIngredient() {
return this.fb.group({
recipe_ingredient: ['', Validators.required ],
recipe_ingredient_quantity: ['', Validators.required ]
});
}
I think all you need is ngModel
in select
tag :
<select class="form-control" formControlName="recipe_ingredient" [(ngModel)]="ri.ingredient">