2017-10-16 12 views
1

に転送するので、ボタンをクリックして新しい選択を追加します。削除すると、配列の最後のメンバーが削除されます。今度は、選択した値を下のリストに移動します。値を動的<select>からリスト

これは私のコードです:

$scope.langInput = { 
    count: 3, 
    values: [1, 2], 
    add: function() { 
     this.values.push(this.count); 
     this.count += 1; 
     console.log(this.values); 
    }, 
    remove: function() { 
     this.values.pop(); 
     this.count -= 1; 
     console.log(this.values); 
    } 
}; 

Thisは、私のコードの作業のデモです。私は選択されたオプションを<ol>リストに移動したい。前もって感謝します。

+0

は、使用してみましたことを要求しかし

<select ng-model="n.selected" ng-change="onChange(n.selected, $index)"> 

'onchange'イベント'list'の選択項目を' ol'に追加しますか? – Krusader

+0

いいえ私はあなたが私のプランカーとショーの例を編集してください。 – BT101

+1

Angularでこれを行う方法はわかりませんが、ここではJS(ES6)の例です。 https://jsfiddle.net/rpneLdma/ – Krusader

答えて

0

あなたにselectを書くことができます:それはオブジェクトのリストであるとはならない整数

$scope.langInput = { 
     count: 3, 
     values: [ 
      { 
      id:1, 
      selected: "eng" 
      }, 
      { 
      id:2, 
      selected: "eng" 
      } 
      ], 
     add: function() { 
      this.values.push({id:this.count,selected: "eng"}); 
      this.count += 1; 
      console.log(this.values); 
     }, 
     remove: function() { 
      this.values.pop(); 
      this.count -= 1; 
      console.log(this.values); 
     } 
    }; 

    $scope.onChange = function(value, index){ 
     $scope.langInput.values[index].selected = value; 
    } 

Demo Plunker

関連する問題