Set default value in select when the ng-model is null

前端 未结 8 2139
悲哀的现实
悲哀的现实 2021-02-05 10:33

I\'m new to angular and i\'m trying to set a default state to select when my ng-model is null. Basically I want to set it to \'None\' if the model is empty. I tried the below co

8条回答
  •  我在风中等你
    2021-02-05 11:30

    What I would suggest you to do is this. Make a function in your controller and check if $scope.item.carType == undefined assign a default value.

    $scope.setDefaultValueForCarType = function () {
          if($scope.item.carType == undefined) {
              $scope.item.carType = "none";
          }
    }
    

    This will work too.

    
                            
        
    提交评论

提交回复
热议问题