python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
<option value="? undefined:undefined ?" selected="selected"></option>

< option value="? undefined:undefined ?" selected="selected" >

Why does AngularJS include an empty option in select?
Adding ng-model to predefined Select element adds undefined option -

AngularJs overrides the "selected" property when we bind the select to a model. If we inspect the rendered DOM we will find that a new item has been added i.e.

 <option value="? undefined: undefined ?"></option>

I think ?undefined:undefined ? should not be set as value. When a user choose nothing they ? undefined: undefined ? will be submitted as value.

You could just initialize it using ng-init such as in the below examples.

Defining that model in the controller -

<script>
    var myApp = angular.module('myApp', [])
        .controller('MyCtrl', ['$scope', function ($scope) {
            $scope.selectedOption = 1;
        }]);
</script>

And other example is -
<div ng-init="selectedOption=1">#TODO</div>

And it looks like -
<select ng-model="selectedOption" required="required" ng-init="selectedOption='1'"
        ng-options="option.value as option.name for option in typeOptions"></select>

Other one example is -
<select ng-model="selectedOption" required="required"
        ng-options="option.value as option.name for option in typeOptions">

    <option style="display:none" value="">select a type</option>
</select>

Other one example is -
<select ng-options="option.value as option.name for option in typeOptions">
    <option value="" ng-if="false"></option>
</select>
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions