简体   繁体   English

将事件绑定用于选择框(角度 9)。您可以查看 gif

[英]using event binding for selectbox (angular 9) .You can look at the gif

I would like the title to change to the selected value from the select , but I'm not sure how to do that.我希望将标题更改为select的选定值,但我不知道该怎么做。 This is the code I have so far:这是我到目前为止的代码:

component.html组件.html

<p>Team:</p>

<select (Change)="selectchange($event)">
  <option *ngFor="let t of teams" [ngValue]="t" >
      {{t.team}}
  </option>
</select>
<h1>your team:<div>{{}}</div></h1>

component.ts组件.ts

teams= [
    { team: 'Galatasaray', value: '4 yıldızlı tek takım' },
    { team: 'Fenerbahçe', value: '3 yıldızlı takım'},
    { team: 'Beşiktaş', value: '3 yıldızlı takım'}
];

An example animation of what I'm looking for我正在寻找的动画示例

Use create a selectedTeam variable and bind it using ngModel .使用创建 selectedTeam 变量并使用ngModel绑定它。

<select [(ngModel)]="selectedTeam" (ngModelChange)="selectchange($event)">
  <option *ngFor="let t of teams" [ngValue]="t" >
      {{t.team}}
  </option>
</select>
<h1>your team:<div>{{selectedTeam?.team + selectedTeam?.value}}</div></h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM