angularjs ng-select ng-options 默认选中项.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div ng-controller="CityController">
<select ng-model="city" value="city.id" ng-options="city.name for city in cities" >
<option value="">Choose City</option>
</select>
<span ng-bind-template="Best City:{{city.name}},id:>>{{city.id}}">
</span>
</div>
</body>
<script type="text/javascript" src="js/angularJs-1.2.16-min.js" ></script>
<script type="text/javascript">
angular.module("myApp",[])
.controller("CityController",function($scope){ $scope.cities=[
{name:"合肥",id:2},
{name:"北京",id:3},
{name:"上海",id:4},
{name:"舒城",id:5},
{name:"纽约",id:6},
{name:"络上几",id:7}
]; for(var i in $scope.cities){
if($scope.cities[i].id==4){//将d是4的城市设为选中项.
$scope.city=$scope.cities[i];
break;
}
}
}); </script>
</html>

注意:
1.这里的的value不是我们给的值.而是循环的索引.
2.ng-model绑定我们的选中项.
3.默认选中项要在controler中指定,并且要和ng-model关联.
angularjs ng-select ng-options 默认选中项.的更多相关文章
- 使用val()方法设置表单中的默认选中项
有时候我们展示给用户的表单中的checkbox,radio,selec等标签的一些项是默认选中的.比方:当用户改动文章的时候,假设相应的栏目为下拉框的话,那么它的默认选中值应该是原来的栏目位置. 能够 ...
- Jquery 根据value值设置下拉列表(select)默认选中项
方法一: $("#selIndustyType option[value='1']").attr("selected", "selected" ...
- html <select> 用JS控制默认选中项
<html> <head> <!--禁止页面缓存--><meta http-equiv="content-type" content=&q ...
- laravel中select2多选,初始化默认选中项
项目中有发送消息功能,需要能通过搜索,多选用户,来指定发送人.使用 select2 插件来完成. select2 的 html 代码如下: <div class="form-group ...
- angularjs的select使用及默认选中
1 ng-model="standardCourse.showHours"代替name 2 ng-selected = "1"代替selected=" ...
- Android RadioGroup设置默认选中项
今天有人问.Android 里面 RadioGroup里面有两个RadioButton怎么设置默认值? 第一个RadioButton设置 android:checked="true" ...
- JQuery Mobile - 动态修改select选择框的选中项
<label for="day">选择天</label> <select name="day" id="day" ...
- easyui combobox默认选中项
今天写前端代码发现combobox还挺难搞, $("#select_Dic").combobox({ url: "http: ...
- @Html.DropDownListFor默认选中项
http://q.cnblogs.com/q/73902/ 项目使用mvc4,给dropDownList指定默认值未选中 页面代码是: 1.未有默认选中值 Html.DropDownListFor(m ...
随机推荐
- shell知识点
各个项目以实践为主.原理及更多细节介绍,请查看官方文档: 例如:bash,grub,postfix,pam,fastcgi,httpd,rsync等诸多项目. 各种总结表格 http://www.cn ...
- ant脚本编写
使用ant脚本前的准备 1.下载一个ant安装包.如:apache-ant-1.8.4-bin.zip.解压到E盘. 2.配置环境变量.新增ANT_HOME:E:\apache-ant-1.8.4:P ...
- Spring和SpringMVC的区别
spring 是是一个开源框架,是为了解决企业应用程序开发,功能如下◆目的:解决企业应用开发的复杂性◆功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能◆范围:任何Java应用简单 ...
- jsp常用指令
Jsp包含三个编译指令和七个动作指令. 三个编译指令为:page.include.taglib. 七个动作指令为:jsp:forward.jsp:param.jsp:include.jsp:plugi ...
- Android 不同文件名介绍
Android 不同文件名介绍
- 获取在线人数 CNZZ 和 51.la
string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...
- Struts2 - Study 1
领略下传说中的Struts2,写了个小例子,有点意思.比起.net中的MVC有意思的在于它是你自己一步步去配置实现,想怎么搞就怎么搞,.net的MVC,它干了什么事你完全不知,只不过知道怎么用而已. ...
- IOS开发-UITextField代理常用的方法总结
1.//当用户全部清空的时候的时候 会调用 -(BOOL)textFieldShouldClear:(UITextField *)textField: 2.//可以得到用户输入的字符 -(BOOL)t ...
- js判断输入框的范围,并且只能输入数字
<input type="text" onkeyup="javascript:this.value=this.value.replace(/[^\d]/g,''); ...
- Python基础教程【读书笔记】 - 2016/7/10
希望通过博客园持续的更新,分享和记录Python基础知识到高级应用的点点滴滴! 第五波:第1章 基础知识 [总览] 介绍如何得到所需的软件,然后讲一点点算法及其主要的组成.学习变量variable ...