Trigger click on first option in select in angular 2

时间:2016-06-10 16:12:50

标签: javascript typescript angular

this is my select in html :

<select id="editProfileForm:AttributesList" 
              name="editProfileForm:AttributesList" 
              size="6" class="allLists" 
              [(ngModel)]="atr1"  >
   <option *ngFor="#attr of attributes"(click)="onSelect(attr, attr.domainDiscrete)">
        {{attr.name}}              
   </option>
</select>

this is my code in component :

onSelect(attclickname: Attribut, statusDiscret: boolean) 
 { 
 this.selectedAttr = attclickname; 
 this._discret = statusDiscret;

 }

when I click on the option elements (ie the attribute name), I get the operators and values of this attribute, I want the first option or click Default

1 个答案:

答案 0 :(得分:0)

<option>元素不会触发click事件。您需要在(click)元素上应用<select>绑定。

另见onclick on option tag not working on IE and chrome