首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角度-在下拉列表中设置选定值

角度-在下拉列表中设置选定值
EN

Stack Overflow用户
提问于 2018-08-01 21:13:56
回答 1查看 12.6K关注 0票数 1
代码语言:javascript
复制
<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,因此未选择该值

代码语言:javascript
复制
ingredient.id == ri.ingredient 

有谁能带路吗?

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

代码语言:javascript
复制
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 ]
    });
  } 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-02 12:38:09

我认为您所需要的就是select标签中的ngModel

代码语言:javascript
复制
<select class="form-control" formControlName="recipe_ingredient" [(ngModel)]="ri.ingredient">
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51634246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档