Kei
Kei

Reputation: 315

AngularJS - ng-repeat default value for select option

I have a form where a user needs to select the type of shifts for two weeks. What I need to do is to set UNIQUE default values for each cell, e.g. Day 1: D, Day2:N, etc.. How can I achieve this?

fiddle: https://jsfiddle.net/fujik8467/axnm0cy9/24/

Upvotes: 0

Views: 1581

Answers (1)

Parminder Singh
Parminder Singh

Reputation: 351

You can use this code:

 <select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[0]">

The above will always select first option but we can make this random using this code: $scope.GetRandomIndex = function() { return Math.floor((Math.random()*3)+1); }

html code:

<select ng-model="day.selectedShiftType" ng-options="shift as shift.strId for shift in shifts" ng-init="day.selectedShiftType = shifts[GetRandomIndex()]">

Upvotes: 1

Related Questions