AngularJS學習筆記之ng-options指令
1.基本下拉效果(lable for value in array)
其中select標簽中的ng-model屬性必須有,其值為選中的對象或屬性值。
<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: '圓領短袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領短袖',
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: '圓領短袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領短袖',
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: '圓領長袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領短袖',
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: '圓領長袖',
ProductColor: '黃'
},{
id: 10003,
MainCategory: '女',
ProductName: '圓領短袖',
ProductColor: '黃'
}];
}]);
效果:http://runjs.cn/detail/nhi8ubrb
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
- angularjs select 賦值 ng-options配置方法
- AngularJS基礎 ng-model-options 指令簡單示例
- Angular中ng-options下拉數(shù)據(jù)默認值的設定方法
- AngularJS中ng-options實現(xiàn)下拉列表的數(shù)據(jù)綁定方法
- angular指令筆記ng-options的使用方法
- AngularJS動態(tài)綁定ng-options的ng-model實例代碼
- 詳解使用angularjs的ng-options時如何設置默認值(初始值)
- angularJs中ng-model-options設置數(shù)據(jù)同步的方法
相關文章
Angular4.x通過路由守衛(wèi)進行路由重定向實現(xiàn)根據(jù)條件跳轉到相應的頁面(推薦)
這篇文章主要介紹了Angular4.x通過路由守衛(wèi)進行路由重定向,實現(xiàn)根據(jù)條件跳轉到相應的頁面,這個功能在網(wǎng)上商城項目上經(jīng)常會用到,下面小編給大家?guī)砹私鉀Q方法一起看看吧2018-05-05
使用AngularJS創(chuàng)建自定義的過濾器的方法
這篇文章主要介紹了使用AngularJS創(chuàng)建自定義的過濾器的方法,AngularJS是非常熱門的JavaScript庫,需要的朋友可以參考下2015-06-06
Angular?服務器端渲染應用常見的內(nèi)存泄漏問題小結
這篇文章主要介紹了Angular?服務器端渲染應用一個常見的內(nèi)存泄漏問題,主要包括屏幕閃爍問題,出現(xiàn)閃爍的原因,在于 Angular 不知道如何重用它在服務器上成功渲染的內(nèi)容,本文給大家介紹的非常詳細,需要的朋友一起學習下吧2022-06-06
ionic+AngularJs實現(xiàn)獲取驗證碼倒計時按鈕
本篇文章主要介紹了ionic+AngularJs實現(xiàn)獲取驗證碼倒計時按鈕,具有一定的參考價值,有興趣的可以了解一下。2017-04-04
Angular中使用ui router實現(xiàn)系統(tǒng)權限控制及開發(fā)遇到問題
這篇文章主要介紹了Angular中使用ui router實現(xiàn)系統(tǒng)權限控制及開發(fā)遇到問題的相關資料,本文分步驟介紹的非常詳細,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
angularjs $http實現(xiàn)form表單提交示例
這篇文章主要介紹了angularjs $http實現(xiàn)form表單提交示例,非常具有實用價值,需要的朋友可以參考下2017-06-06
AngularJs html compiler詳解及示例代碼
本文主要介紹AngularJs html compiler的知識講解,這里整理了相關資料及相關示例代碼,有興趣的小伙伴可以參考下2016-09-09

