Angular 用改变方法选择角度值

Angular 用改变方法选择角度值,angular,select,bootstrap-4,Angular,Select,Bootstrap 4,我有一个select组件和一个函数来获取select的值 问题是该值未定义。当我使用角材料时,它工作了,但现在我使用引导,停止了工作 Html: 角色 顶部 丛林 中间 机器人程序 支持 填满 updatePlayerRole(值,i){ console.log(value.value); console.log(值); 控制台日志(i); this.team[i].role=value.value; 这个.checkIfFormIsCompleted(); } 我做错了什么?或者更改方法

我有一个select组件和一个函数来获取select的值

问题是该值未定义。当我使用角材料时,它工作了,但现在我使用引导,停止了工作

Html:


角色
顶部
丛林
中间
机器人程序
支持
填满
updatePlayerRole(值,i){
console.log(value.value);
console.log(值);
控制台日志(i);
this.team[i].role=value.value;
这个.checkIfFormIsCompleted();
}

我做错了什么?或者更改方法未正确使用?

请按照以下步骤开始:

  • 在component.ts文件中为选项创建字符串数组
  • 在html中的数组上循环以创建选项
  • $event.target.value
    传递给您的
    (更改)=“updatePlayerRole($event.target.value)”
  • 下面是一个简单的例子:

    组件技术

    export class AppComponent  {
      options: string[] = [
        'top',
        'jungle',
        'mid',
        'bot',
        'support',
        'fill'
      ];
    
      selectedOption: string = '';
    
      updatePlayerRole(value: string) {
        console.log(value);
        this.selectedOption = value;
      }
    
    }
    
    然后在component.html中

    <select (change)="updatePlayerRole($event.target.value,i)">
      <option disabled>Please Select</option>
      <option *ngFor="let option of options" [value]="option">{{ option }} 
      </option>
    </select>
        
    <p>Selected Option: <strong>{{selectedOption || 'nothing is selected'}}</strong></p>
    
    
    请选择
    {{option}}
    所选选项:{{selectedOption | |“未选择任何内容”}

    这将在组件中的
    updatePlayerRole()
    方法中获得一个字符串值

    下面是一个stackblitz示例: