ng-options默认选中
来源:互联网 发布:汽车调色软件 编辑:程序博客网 时间:2024/06/02 00:26
第一种方法:绑定类型 => $scope.a
<!DOCTYPE html><html><head> <meta charset="utf-8"> <script src="https://cdn.bootcss.com/angular.js/1.6.6/angular.min.js"></script></head><body><div ng-app="myApp" ng-controller="myCtrl"> <select ng-init="selectPerson=persons['caohui']" ng-model="selectPerson" ng-options="x for (x,y) in persons"> </select> <p> 年龄:{{selectPerson.age}} </p> <p> 性别:{{selectPerson.sex}} </p> <p> 月薪:{{selectPerson.salary}} </p></div><script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.persons = { 张三: { age: 27, sex: 'male', salary: 10000 }, 王二: { age: 20, sex: 'male', salary: 500 }, 李四: { age: 24, sex: 'female', salary: 6000 } } })</script></body></html>
第二种方法:绑定类型 => $scope.app.a
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>Example - example-select-ngrepeat-production</title> <script src="https://cdn.bootcss.com/angular.js/1.5.0/angular.min.js"></script> <script> angular.module('ngrepeatSelect', []) .controller('ExampleController', ['$scope', function($scope) { $scope.selectIndex = {a: 1}; $scope.arr = [ {a: '1', value: ' A'}, {a: '2', value: ' B'}, {a: '3', value: 'C'} ]; }]); </script></head><body ng-app="ngrepeatSelect"> <div ng-controller="ExampleController"> <form name="myForm"> <label for="repeatSelect"> Repeat select: </label> <select name="repeatSelect" id="repeatSelect" ng-model="selectIndex.a"> <option ng-repeat="option in arr" value="{{$index}}" ng-value="{{$index}}">{{option.value}}</option> </select> </form> <hr> <tt>selectIndex = {{selectIndex.a}}</tt> <br/> </div></body></html>
阅读全文
0 0
- ng-options默认选中
- angularjs ng-options指令 默认选择 玩法
- ngular1 ionic1 select ng-options默认选择第一个值。
- angular使用ng-option。默认选中列表第一项
- Angularjs ng-options用法
- angular--ng-options
- angular的ng-options
- ng-options用法详解
- AngularJs ng-options
- ng-options 用法详解
- angular ng-options
- ng-model-options
- ng-options用法详解
- ng-options用法详解
- ng-grid options 一览
- ng-options no-repeat
- ng-options指令语法
- ng-options详解
- NLP02-Gensim语料与向量空间
- Django 注册邮箱验证
- Oracle之一条SQL对应多个执行计划
- 简单servlet第二篇--load-on-startup的用法
- javaSE面试题一,变量,操作符
- ng-options默认选中
- intellij idea svn使用一 导入、更新、提交、解决冲突
- CSS-伪类子代选择器
- Eclipse中创建新的Spring Boot项目
- Linux7 MySQL安装卸载教程
- Android中插件开发篇之----应用换肤原理解析
- Linux oracle监听启动失败
- unity包内的内容读取
- 详解Javascript中正则表达式的使用