AngularJS學(xué)習(xí)筆記之ng-options指令
1.基本下拉效果(lable for value in array)
其中select標(biāo)簽中的ng-model屬性必須有,其值為選中的對象或?qū)傩灾怠?/p>
<div ng-controller="ngselect">
<p>usage:label for value in array</p>
<p>選項,{{selected}}</p>
<select ng-model="selected" ng-options="o.id for o in optData">
<option value="">-- 請選擇 --</option>
</select>
</div>
m1.controller("ngselect",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory: '男',
ProductName: '水洗T恤',
ProductColor: '白'
},{
id: 10002,
MainCategory: '女',
ProductName: '圓領(lǐng)短袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領(lǐng)短袖',
ProductColor: '黃'
}];
}]);
2.自定義下拉顯示名稱(label for value in array)
label可以根據(jù)需要拼接出不同的字符串
<div ng-controller="ngselect2">
<p>usage:label for value in array(label可以根據(jù)需求拼接出不同的字符串)</p>
<p>選項,{{selected}}</p>
<select ng-model="selected" ng-options="(o.ProductColor+'-'+o.ProductName) for o in optData">
<option value="">-- 請選擇 --</option>
</select>
</div>
m1.controller("ngselect2",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory: '男',
ProductName: '水洗T恤',
ProductColor: '白'
},{
id: 10002,
MainCategory: '女',
ProductName: '圓領(lǐng)短袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領(lǐng)短袖',
ProductColor: '黃'
}];
}]);
3.ng-options 選項分組
group by分組項
<div ng-controller="ngselect3">
<p>usage:label group by groupName for value in array</p>
<p>選項,{{selected}}</p>
<select ng-model="selected" ng-options="(o.ProductColor+'-'+o.ProductName) group by o.MainCategory for o in optData">
<option value="">-- 請選擇 --</option>
</select>
</div>
m1.controller("ngselect3",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory: '男',
ProductName: '水洗T恤',
ProductColor: '白'
},{
id: 10002,
MainCategory: '女',
ProductName: '圓領(lǐng)長袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領(lǐng)短袖',
ProductColor: '黃'
}];
}]);
4.ng-options 自定義ngModel的綁定
下面selected的值為optData的id 效果 http://sandbox.runjs.cn/show/nhi8ubrb
<div ng-controller="ngselect4">
<p>usage:select as label for value in array</p>
<p>選項,{{selected}}</p>
<select ng-model="selected" ng-options="o.id as o.ProductName for o in optData">
<option value="">-- 請選擇 --</option>
</select>
</div>
m1.controller("ngselect4",['$scope',function($sc){
$sc.selected = '';
$sc.optData = [{
id: 10001,
MainCategory: '男',
ProductName: '水洗T恤',
ProductColor: '白'
},{
id: 10002,
MainCategory: '女',
ProductName: '圓領(lǐng)長袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領(lǐng)短袖',
ProductColor: '黃'
}];
}]);
效果:http://runjs.cn/detail/nhi8ubrb
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
- angularjs select 賦值 ng-options配置方法
- AngularJS基礎(chǔ) ng-model-options 指令簡單示例
- Angular中ng-options下拉數(shù)據(jù)默認(rèn)值的設(shè)定方法
- AngularJS中ng-options實(shí)現(xiàn)下拉列表的數(shù)據(jù)綁定方法
- angular指令筆記ng-options的使用方法
- AngularJS動態(tài)綁定ng-options的ng-model實(shí)例代碼
- 詳解使用angularjs的ng-options時如何設(shè)置默認(rèn)值(初始值)
- angularJs中ng-model-options設(shè)置數(shù)據(jù)同步的方法
相關(guān)文章
angularjs項目的頁面跳轉(zhuǎn)如何實(shí)現(xiàn)(5種方法)
本篇文章主要介紹了詳解angularjs項目的頁面跳轉(zhuǎn)如何實(shí)現(xiàn) ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05
angular2 ng2 @input和@output理解及示例
本篇文章主要介紹了angular2 ng2 @input和@output理解及示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
Angular中ng-options下拉數(shù)據(jù)默認(rèn)值的設(shè)定方法
本篇文章主要介紹了Angular中ng-options下拉數(shù)據(jù)默認(rèn)值的設(shè)定方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
angular2+nodejs實(shí)現(xiàn)圖片上傳功能
這篇文章主要介紹了angular2+nodejs實(shí)現(xiàn)圖片上傳功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03
Angular實(shí)現(xiàn)的敏感文字自動過濾與提示功能示例
這篇文章主要介紹了Angular實(shí)現(xiàn)的敏感文字自動過濾與提示功能,結(jié)合實(shí)例形式分析了AngularJS針對字符串的輸入判定及實(shí)時顯示相關(guān)操作技巧,需要的朋友可以參考下2017-12-12
Angular刷新當(dāng)前頁面的實(shí)現(xiàn)方法
這篇文章主要介紹了Angular刷新當(dāng)前頁面的實(shí)現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11

