search

Home  >  Q&A  >  body text

angular.js - select如何根据参数显示相应的选项

我的代码如下:

<select ng-model="testV" ng-change="change()">
      <option value="">Any</option>
      <option value="0">0</option>
      <option value="1">1</option>
      <option value="2">2</option>
</select>

如何让selected的选项设置为value等于$scope.testV的项呢?

伊谢尔伦伊谢尔伦2744 days ago556

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-15 17:11:49

    Add this sentence$scope.testV = 2; to the controller and it will display 2 by default.

    $scope.change = function(){
        console.log($scope.testV);
    }
    

    In this way, every time the select value is changed, the console will output the changed value.

    reply
    0
  • Cancelreply