2017-03-24 15 views
0

私は現在angular2を使用しています。typescriptで選択されたチェックボックスの値を取得する方法は?

<select id="color" class="colorDropDown" (change)="signalSelected($event, 'color')"> 
    <option *ngFor="let color of colors" value={{axis}} [selected]="color == channelPropertyModel.color"> 
     {{color}} 
    </option> 
</select> 

マイtypescriptファイルがあるように私は

signalSelected(event: any, selection: string) { 
    //Add the newly entered value and the corresponding field name into the dictionary 
    this.selectedUIInfo[selection] = event.currentTarget.value; 
} 

しかし、メソッドを呼び出していますドロップダウンから任意の色を変更するには

this.colors = ["ORANGE", "WHITE", "RED", "GREEN", "BLUE", "YELLOW", "CYAN", "SKYBLUE"]; 

を次のように私は私のhtmlコードを持っています私はevent.currentTarget.valueで選択された色を取得していません。ドロップダウンから選択した色を取得する方法を提案してください。

+0

サンプルモック以下をご確認ください以下のように選択した項目にチェックするプロパティを使用して、それを割り当てる必要がありますジュソン?データ – Aravind

+0

これは答えとしてどのようにマークされていますか?リンクされたPlunkerのチェックボックスはどこですか? – Aravind

答えて

0

<select [(ngModel)]="selectedCity" (ngModelChange)="onChange($event)" > 
    <option *ngFor="let c of cities" [ngValue]="c"> {{c.name}} </option> 
</select> 

class App { 
    cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}]; 
    selectedCity = this.cities[1]; 

    onChange(city) { 
    alert(city.name); 
    } 
} 

Plunker

0

あなたは

<select [(ngModel)]="selectedElement" (change)="changedval()"> 
    <option *ngFor="let color of colors" [ngValue]="color"> {{color}}</option> 

</select> 

<span *ngFor="let type of types"> 
     <input type="checkbox" [checked]="color===newElement" value="color"> {{color}}<br> 
</span> 




changedval(){ 
    this.newElement=this.selectedElement; 
    console.log(this.newElement) 
    } 

LIVE DEMO

関連する問題