就像人生,面臨許多選擇,AngularJS選單可以怎麼呈現呢?
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; };
隨意留個言吧:)~