Select default option in a dropdown, save the value in the value attribute of the dropdown. Angular.js. Angular.js

前端 未结 3 1339
醉酒成梦
醉酒成梦 2021-01-26 16:31

I have seen infinity of post to try to choose by default an option in a dropdown. But I have not been able to achieve it. I have an array of some countries.

$sco         


        
3条回答
  •  悲哀的现实
    2021-01-26 17:00

    You can add a filter to your controller to get the default region (don't forget to add $filter after $scope):

    $scope.defaultValue = $filter('filter')($scope.regions, {code: $scope.selectThisId.id}, true)[0];
    

    and then add this to your select in your view

    ng-init="select = defaultValue"
    

    Demo

提交回复
热议问题