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)文章
Angular4.x通過路由守衛(wèi)進(jìn)行路由重定向?qū)崿F(xiàn)根據(jù)條件跳轉(zhuǎn)到相應(yīng)的頁面(推薦)
這篇文章主要介紹了Angular4.x通過路由守衛(wèi)進(jìn)行路由重定向,實(shí)現(xiàn)根據(jù)條件跳轉(zhuǎn)到相應(yīng)的頁面,這個功能在網(wǎng)上商城項目上經(jīng)常會用到,下面小編給大家?guī)砹私鉀Q方法一起看看吧2018-05-05
使用AngularJS創(chuàng)建自定義的過濾器的方法
這篇文章主要介紹了使用AngularJS創(chuàng)建自定義的過濾器的方法,AngularJS是非常熱門的JavaScript庫,需要的朋友可以參考下2015-06-06
Angular?服務(wù)器端渲染應(yīng)用常見的內(nèi)存泄漏問題小結(jié)
這篇文章主要介紹了Angular?服務(wù)器端渲染應(yīng)用一個常見的內(nèi)存泄漏問題,主要包括屏幕閃爍問題,出現(xiàn)閃爍的原因,在于 Angular 不知道如何重用它在服務(wù)器上成功渲染的內(nèi)容,本文給大家介紹的非常詳細(xì),需要的朋友一起學(xué)習(xí)下吧2022-06-06
ionic+AngularJs實(shí)現(xiàn)獲取驗證碼倒計時按鈕
本篇文章主要介紹了ionic+AngularJs實(shí)現(xiàn)獲取驗證碼倒計時按鈕,具有一定的參考價值,有興趣的可以了解一下。2017-04-04
詳談angularjs中路由頁面強(qiáng)制更新的問題
下面小編就為大家?guī)硪黄斦刟ngularjs中路由頁面強(qiáng)制更新的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04
Angular中使用ui router實(shí)現(xiàn)系統(tǒng)權(quán)限控制及開發(fā)遇到問題
這篇文章主要介紹了Angular中使用ui router實(shí)現(xiàn)系統(tǒng)權(quán)限控制及開發(fā)遇到問題的相關(guān)資料,本文分步驟介紹的非常詳細(xì),具有參考借鑒價值,需要的朋友可以參考下2016-09-09
angularjs $http實(shí)現(xiàn)form表單提交示例
這篇文章主要介紹了angularjs $http實(shí)現(xiàn)form表單提交示例,非常具有實(shí)用價值,需要的朋友可以參考下2017-06-06
AngularJs html compiler詳解及示例代碼
本文主要介紹AngularJs html compiler的知識講解,這里整理了相關(guān)資料及相關(guān)示例代碼,有興趣的小伙伴可以參考下2016-09-09

