将动态值 <select> 的值传递给列表

Convey value from dynamic <select> to list

因此,在单击按钮时我添加了新的 select,在删除时我删除了数组的最后一个成员。现在我想将 selected 值移动到下面的列表中。

这是我的代码:

  $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正在演示我的代码。我想将 selected 选项移动到 <ol> 列表。提前致谢。

您可以将 select 写为:

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

但是它要求 langInput.values 应该是对象列表而不是整数

$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