国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

AngularJS實現select的ng-options功能示例

2019-11-19 16:05:57
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大同县| 平凉市| 台前县| 沈丘县| 临湘市| 长治市| 嘉荫县| 循化| 梁平县| 革吉县| 阿拉善右旗| 裕民县| 宁化县| 疏勒县| 安国市| 清流县| 吉林市| 崇阳县| 林芝县| 蓬溪县| 工布江达县| 宣武区| 额尔古纳市| 凤冈县| 河源市| 邹平县| 拜泉县| 彩票| 遵义市| 会东县| 奉贤区| 贡嘎县| 杭州市| 南阳市| 邛崃市| 黄陵县| 襄樊市| 肥城市| 建湖县| 长兴县| 新源县|