Just My Life & My Work

[Ionic][AngularJS] 選單

就像人生,面臨許多選擇,AngularJS選單可以怎麼呈現呢?

[Ionic][AngularJS] 選單.png

View的部分可以這麼寫:

/**
 Theme: AngularJS Select
 IDE: Sublime
 Language: Javascript
 Date: 106/07/13
 Author: HappyMan
 Blog: https://cg2010studio.com/
 */

    <select ng-init="somethingHere = kidList[0]"
ng-model="somethingHere"
ng-options="option.Name for option in kidList"
ng-change="select()">
    </select>

  • ng-init為預設值
  • ng-model為被選擇的變數
  • ng-options為選擇項目
  • ng-change為選擇後的行為

Controller可以這麼做:

/**
 Theme: AngularJS Select
 IDE: Sublime
 Language: Javascript
 Date: 106/07/13
 Author: HappyMan
 Blog: https://cg2010studio.com/
 */

  $scope.kidList = JSON.parse(AuthService.storageGet('kidList'));

  $scope.select = function () {
       $scope.selectId = $scope.somethingHere.Id;
  };

參考:getting the ng-object selected with ng-change

隨意留個言吧:)~

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲