Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用“角度”获取下拉列表值_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 使用“角度”获取下拉列表值

Javascript 使用“角度”获取下拉列表值,javascript,angular,typescript,Javascript,Angular,Typescript,有这样的要求,一旦我们点击按钮,就需要得到行的下拉值。我尝试了下面的代码,并获得了选定的下拉列表值,但相同的下拉列表选项也适用于其余的下拉列表。有没有办法只更新选定的下拉列表而不是全部 .ts .html 您应该使用[ngModel]。为此,首先将人员添加映射到属性检查和测试 获取数据后,使用map添加属性 this.http.get(dataUrl).subscribe(response => { this.persons = response.data.map(x=>({..

有这样的要求,一旦我们点击按钮,就需要得到行的下拉值。我尝试了下面的代码,并获得了选定的下拉列表值,但相同的下拉列表选项也适用于其余的下拉列表。有没有办法只更新选定的下拉列表而不是全部

.ts

.html

您应该使用[ngModel]。为此,首先将人员添加映射到属性检查和测试

获取数据后,使用map添加属性

this.http.get(dataUrl).subscribe(response => {
  this.persons = response.data.map(x=>({...x,check:false,test:'test'}));
  this.dtTrigger.next();
});
然后您可以更改您的.html,查看如何禁用您使用的[disabled]=!person.check?true:null且[ngModel]=person.check且[ngModel]=person.test

请注意,您不需要jQuery或click-in选项,并且可以在change函数中传递test的值


您的

GetElementsByCassName返回元素列表,该列表没有value属性。另外,看起来您使用的是angular,因此如果您正确绑定了属性,就不需要调用DOM方法。您使用的是angular,因此请在标记中而不是在typescript中提及它。首先,您不为该选项赋值,其次,您所有的选项都在ProductHeader变量中,第三,您可以将[ngModel]赋值给select,该select将包含实际选定的值。它还可以存储对象,不仅仅是字符串|数字。现在我得到了警告下拉选项,但相同的选项也更新了其余的下拉列表。是否只更新选定的下拉列表?请建议。我也参加了闪电战。
<td>   
          <select [(ngModel)]="selectedLevel" (change)="selected()">
  <option *ngFor="let prod of ProductHeader">{{prod.name}}</option>
</select>
     <button class="select" (click)="saveData()">Selected Option</button>   
</td>
this.http.get(dataUrl).subscribe(response => {
  this.persons = response.data.map(x=>({...x,check:false,test:'test'}));
  this.dtTrigger.next();
});
  <tr *ngFor="let person of persons">
    <td>
        <input [(ngModel)]="person.check" type="checkbox" 
               class="checkboxCls" name="id"></td>
    <td>{{ person.id }}</td>
    <td>
    <select [disabled]="!person.check?true:null" [(ngModel)]="person.test" 
            (change)="selected(person.test)">
      <option *ngFor="let prod of ProductHeader" [value]="prod.name" >{{prod.name}}</option>
    </select>
    </td>