Sharpeye500
Sharpeye500

Reputation: 9073

<select> element - Using `ngRepeat` to generate select options

Bind data to each row and also change the bound data based on condition

I need bind data to every row in angular & also edit the same bound data based on conditions.

<select id="subject" name="subject"  ng-model="subjectName">
 <option ng-repeat="s in subjects" value="{{s.Id}"
         ng-init="subjectName=physics">{{s.Name}}</option>
 </select>

I am binding list of subjects to every week, so, it will look like

Daily                              <<Drop down with list of subjects>>

1/1/2015                        English, Mathematics, Chemistry
1/2/2015                        English, Mathematics, Chemistry
1/3/2015                        English, Mathematics, Chemistry
1/4/2015                        English, Mathematics, Chemistry
1/5/2015                        English, Mathematics, Chemistry

In another screen, user assigns to only few subjects for particular date range.

Start date:1/1/2015
End date: 1/3/2015
Only assigned subject: English

So, the expected result is

Daily                              <<Drop down with list of subjects>>

1/1/2015                        English
1/2/2015                        English
1/3/2015                        English
1/4/2015                        English, Mathematics, Chemistry
1/5/2015                        English, Mathematics, Chemistry

I want items to be removed from the drop down for each row(based on each date entry).

How do i bind this scenario in angular, i am beginner in angular, so need some help.

Upvotes: 0

Views: 51

Answers (1)

Immanuel Kirubaharan
Immanuel Kirubaharan

Reputation: 1104

Try something like this below code, also check this sample plunker for you example scenario.

Template:

<select ng-model="item.subject" ng-options="sub.id as sub.name for sub in SubjectList">
   <option value="">Select Subject</option>
</select>

Controller:

  $scope.SubjectList = [{
    id: 1,
    name: 'English'
  }, {
    id: 2,
    name: 'Mathematics'
  }, {
    id: 3,
    name: 'Chemistry'
  }];

Upvotes: 1

Related Questions