使用AngularJS进行选择的占位符 [英] Placeholder for select with AngularJS

查看:161
本文介绍了使用AngularJS进行选择的占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过select获得占位符的想法。

I can't get a placeholder idea with select. With the below the first entry is still blank.

<select class="form-control" ng-model="refData" required>
     <option ng-repeat="d in refData">
          {{d.value}}
     </option>
     <option value="" disabled hidden selected>View current values</option>
</select>


推荐答案

像这样 demo小提琴。有一个占位符选项,默认情况下会被选中,但不是真正的选项。另请查阅 ngSelect文档

Try it like in this demo fiddle. There is an placeholder option included which is selected by default but ain't a real option to select. Also check the ngSelect documentation.

<div ng-controller="MyCtrl">
    <select name="mySelect" 
            id="mySelect"
            ng-options="option.name for option in refData track by option.id"
            ng-model="selectedOption">
         <option value="" disabled selected>View current values</option>
     </select>
</div>



AngularJS应用程序



AngularJS application

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', function ($scope) {
    $scope.refData = [
      {id: '1', name: 'Option A'},
      {id: '2', name: 'Option B'},
      {id: '3', name: 'Option C'}
    ];

    $scope.selectedOption =  "";
});

这篇关于使用AngularJS进行选择的占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆