angular实现select的ng-options4
ng实现简单的select
<div ng-controller="ngSelect">
<select ng-model="vm.selectVal" ng-options="o.title for o in vm.optionsData">
<option value="">请选择</option>
</select>
</div>

var app = angular.module("app",[]);
app.controller("ngSelect",function($scope){
var vm = $scope.vm = {};
//数组对象用来给ng-options遍历
vm.optionsData = [{
title : "angularJs"
},{
title : "emberJs"
},{
title : "backboneJs"
},{
title : "knockoutJs"
}];
})

给ng-options自定义option的value值
<select ng-model="vm.selectVal" ng-options="o.id as o.title for o in vm.optionsData" ng-change="selectChange()">
<option value="">请选择</option>
</select>
添加了id属性作为option的value
你可能会在页面视图看到option生成的value为0,1,2,3,是因为angular会自动添加索引为value的值
让我们来个ng-change事件监控来看看

vm.optionsData = [{
id : 4543,
title : "angularJs"
},{
id : 546,
title : "emberJs"
},{
id : 456,
title : "backboneJs"
},{
id : 75,
title : "knockoutJs"
}];
$scope.selectChange = function(){
//添加了ng-change事件来试试id值的输出
console.log(vm.selectVal);
}
angular实现select的ng-options4的更多相关文章
- angular使用select时要注意的坑
一.错误使用产生的坑--留白 公司前段时间要搞一个后台系统,为了快选了angular,在使用select标签的时候碰到一个小问题,首先我们先来看坑图,如图1所示. 如图所示,出现了留白,也就是当我们使 ...
- angular实现select的ng-options
html <div ng-controller="ngSelect"> <select ng-model="vm.selectVal" ng- ...
- Angular笔记-select
--select-- 设置默认选中值方法: <select ng-model="url" ng-options="x.url as x.site for x in ...
- [Angular] The Select DOM Event and Enabling Text Copy
When we "Tab" into a input field, we want to select all the content, if we start typing, i ...
- angular报错:angular.min.js:118Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq
报错代码如下: <div ng-controller="HelloAngular"> <p>{{greeting.text}},angular</p& ...
- angular关于select的留白问题
Angular select留白的问题 小白的总结,大神勿喷:需要转载请说明出处,如果有什么问题,欢迎留言 总结:出现留白说明你的ng-model的值在option的value中没有对应的值: 一.直 ...
- [Angular 2] Select From Multiple Nested Angular 2 Elements
You have complete control over the elements you nest inside of your component instance by using sele ...
- angular清除select空格
<select class="form-control" id="policy_set_id" ng-model="add.poli ...
- Angular CLI 启动 版本ng 4
npm install -g angular-cli ng -v ng new project_name cd project_name ng serve 浏览器打开输入 localhost:4200
随机推荐
- php 分页类(2)
<?phpinclude("connection.php");$perNumber=10; //每页显示的记录数$page=$_GET['page']; //获得当前的页面值 ...
- js导入插件注意事项.txt
网上收集的答案如下:==============================================1)确认js真的被引用到2)确认js引用顺序没问题3)确认js代码里的括号等都匹配,不会 ...
- play框架概述
今天是来百度实习的第四天,在项目过程中mentor说会用到play框架,当时就一个晕啊.Java还有一个叫play框架,作为一个从大三开始用java的重度javaer,居然不知道这个框架的存在,内心一 ...
- 【01-14】java ThreadLocal工具类
自定义ThreadLocal package concurrent; import java.util.HashMap; import java.util.Map; /** * @author alo ...
- 图片(img标签)大小自适应
$(function(){ var myimg,oldwidth,oldheight; var maxwidth=249; var maxheight=187; var imgs = document ...
- python datetime时间差
import datetime import time d1 = datetime.datetime(2005, 2, 16) d2 = datetime.datetime(2004, 12, 31) ...
- qq客服问题
angularJs会给ng-href的不正常跳转,会 添加unsafe的前缀.原因是angular对href是有安全检查的,只能生成它认为安全的链接.解决方法如下: 在config.js中注入 fun ...
- linux 进程监控和自动重启的简单实现
目的:linux 下服务器程序会因为各种原因dump掉,就会影响用户使用,这里提供一个简单的进程监控和重启功能. 实现原理:由定时任务crontab调用脚本,脚本用ps检查进程是否存在,如果不存在则重 ...
- linux下编译安装apache
在linux(CentOS6.5)上安装Apache,要首先确保以下程序事先安装 apr:The mission of the Apache Portable Runtime (APR) projec ...
- cordova环境配置步骤
1.安装node.js环境 官网: http://nodejs.org/ 2.sudo npm install -g cordova(一般会失败,需要用FQ安装或者用淘宝镜像安装,可以用FQ就可以不用 ...