1
<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; 但是下面的代码在上面的代码中没有返回true,所以没有选择值

ingredient.id == ri.ingredient 

谁能指导

我的 ts 文件中的代码如下:

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 ]
    });
  } 
4

1 回答 1

3

我认为您需要的只是ngModel标签select

<select class="form-control" formControlName="recipe_ingredient" [(ngModel)]="ri.ingredient">

工作演示

于 2018-08-02T04:38:09.473 回答