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
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.
<select ng-init="item.carType='none'" ng-model="item.carType">
Often happens that your ng-model="item.carType"
doesn't match any of the select option keys because of the wrong case.
For example: item.cartType
is "Manual"
but in the options you have an option <option value="manual">Manual</option>
in this case it won't work and in the console output you'll see something like this: <option value="? string:Manual ?"></option>
So, either correct your data model or your select option value:
<option value="Manual">Manual</option>