This is framework has features what first element in dropdown will be empty.
By design, it must be an element with label as 'Select from dropdown'.
Problem:
The original code:
<select ng-model="feed.config">
<option ng-repeat="template in configs" ng-selected="$first">{{template.name}}</option>
</select>
Because this is versions is intermediate, solutions as
<option value="" style="display: none"></option>
or
<option value="" ng-if = "false"></option>
or<option value="" ng-show = "false"></option>
Same situation with all solutions from this is URL:
- https://ask-dev.ru/info/13515/why-does-angularjs-include-an-empty-option-in-select
- https://jsfiddle.net/MTfRD/3/
- https://stackoverflow.com/questions/44639911/how-to-remove-an-empty-option-after-a-filter-modifies-the-drop-down-list-in-angu
- https://syntaxfix.com/question/11449/remove-blank-option-from-select-option-with-angularjs
this solution will be works correctly:
<select ng-model="model.id" convert-to-number>
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
{{ model }}
angular.module('nonStringSelect', [])
.run(function($rootScope) {
$rootScope.model = { id: 2 };
})
.directive('convertToNumber', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(val) {
return parseInt(val, 10);
});
ngModel.$formatters.push(function(val) {
return '' + val;
});
}
};
});
And result:- ngSelected: https://docs.angularjs.org/api/ng/directive/ngSelected
- $first: https://docs.angularjs.org/api/ng/directive/ngRepeat
- Examples with some problem: https://syntaxfix.com/question/11449/remove-blank-option-from-select-option-with-angularjs
- Docs for version: https://code.angularjs.org/1.4.3/docs/api/ng/directive/select
No comments:
Post a Comment