您好,登錄后才能下訂單哦!
本文實例講述了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> <h2 class="title">發帖</h2> <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程序設計有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。