AngularJS实现select的ng-options功能示例
程序员文章站
2022-11-25 11:28:03
本文实例讲述了angularjs实现select的ng-options功能。分享给大家供大家参考,具体如下:
controller
.controller('m...
本文实例讲述了angularjs实现select的ng-options功能。分享给大家供大家参考,具体如下:
controller
.controller('maincontroller', function($scope, $http, $ionicmodal, $timeout) { var post = {}; $http.get("data/themedata.json") .success(function(response) { $scope.themedata = response.themedata; }); $ionicmodal.fromtemplateurl('templates/post.html', { scope: $scope }).then(function(modal) { $scope.modal = modal; }); $scope.postshow = function() { post = $scope.post = {}; $scope.modal.show(); }; $scope.cancelpost = function() { $scope.modal.hide(); }; $scope.dopost = function() { console.log('dopost-----'); console.log(post); $timeout(function() { $scope.cancelpost(); }, 1000); }; })
html
<ion-modal-view> <form name="post_form"> <ion-header-bar> <button class="button button-icon icon ion-ios-arrow-back" ng-click="cancelpost()"></button> <h1 class="title">发帖</h1> <button class="button button-icon icon ion-forward" ng-disabled="post_form.$invalid" ng-click="dopost()"></button> </ion-header-bar> <ion-content> <div class="list"> <label class="item item-input mylabel"> <input type="text" placeholder="标题" ng-model="post.title" required/> </label> <label class="item item-input mylabel2"> <select class="myselect col" ng-model="post.kmforumcategoryid" ng-options="theme.id as theme.name for theme in themedata" required> <!-- 添加了id属性作为option的value --> <option value="">选择主题分类</option> </select> </label> <label class="item item-input mylabel"> <textarea class="post_content" placeholder="内容" ng-model="post.content" required></textarea> </label> </div> </ion-content> </form> </ion-modal-view>
实现的dom
<select class="myselect col ng-pristine ng-untouched ng-invalid ng-invalid-required" ng-model="post.kmforumcategoryid" ng-options="theme.id as theme.name for theme in themedata" required=""> <option value="">选择主题分类</option> <option value="0" label="主题111">主题111</option> <option value="1" label="主题222">主题222</option> <option value="2" label="有没问题">有没问题</option> <option value="3" label="测试112">测试112</option> <option value="4" label="你好">你好</option> <option value="5" label="主题">主题</option> <option value="6" label="测试000">测试000</option> </select>
可以用ng-change事件监控来看看输出的是什么
更多关于angularjs相关内容感兴趣的读者可查看本站专题:《angularjs指令操作技巧总结》、《angularjs入门与进阶教程》及《angularjs mvc架构总结》
希望本文所述对大家angularjs程序设计有所帮助。
下一篇: Angular如何引入第三方库的方法详解
推荐阅读
-
微信小程序实现的日期午别医生排班表功能示例
-
JS实现的Object数组去重功能示例【数组成员为Object对象】
-
Android开发使用json实现服务器与客户端数据的交互功能示例
-
Android编程实现变化的双重选择框功能示例
-
Android编程实现的短信编辑器功能示例
-
微信小程序导航栏滑动定位功能示例(实现CSS3的positionsticky效果)
-
微信小程序使用map组件实现检索(定位位置)周边的POI功能示例
-
python,Django实现的淘宝客登录功能示例
-
微信小程序MUI导航栏透明渐变功能示例(通过改变rgba的a值实现)
-
C#实现的上传图片、保存图片、加水印、生成缩略图功能示例