javascript - Angularjs md-select not set placeholder -
following code of <md-select/>
not showing placeholder when added placeholder="select type"
<md-select ng-model="ctrl.number" ng-model-options="{trackby: '$value.id'}" placeholder="select type"> <md-option ng-repeat="n in ctrl.numbers" ng-value="n"> {{ n.value }} </md-option> </md-select>
but work below code
<md-select ng-model="ctrl.number" placeholder="select type"> <md-select-label>{{ ctrl.number.value }}</md-select-label> <md-option ng-repeat="n in ctrl.numbers" ng-value="n">{{ n.value }}</md-option> </md-select>
js code
(function () { 'use strict'; angular .module('myapp') .controller('appctrl', function() { var _this = this; _this.number = {id: 2, value: "two"}; _this.numbers = [ {id: 0, value: "zero"}, {id: 1, value: "one"}, {id: 2, value: "two"}, {id: 3, value: "three"}, {id: 4, value: "four"}, {id: 5, value: "five"} ]; }); })();
can please let me know wrong first , how set placeholder
in case ?
<md-select ng-model="ctrl.number" ng-model-options="{trackby: '$value.id'}" placeholder="select type"> <md-option value="">select type</md-option> <md-option ng-repeat="n in ctrl.numbers" ng-value="n"> {{ n.value }} </md-option>` </md-select>
your code works fine. placeholder displays when not selected. should add "md-option value="" unselect.
Comments
Post a Comment