I am encountering an issue with my Angular.js controller file where I am unable to retrieve any value from the drop-down list. The error message being displayed is:
$scope.subname is undefined
Below is a breakdown of my code.
index.html
<table class="table table-bordered table-striped table-hover" id="dataTable" ng-app="myApp" ng-controller="tableCtrl">
<tr>
<td width="100" align="center">Time <i class="fa fa-long-arrow-right"></i>
<BR>Day <i class="fa fa-long-arrow-down"></i>
</td>
<td width="100" align="center" ng-repeat="hour in hours" ng-bind="hour"></td>
</tr>
<tbody id="detailsstockid">
<tr ng-repeat="days in noOfDays">
<td width="100" align="center" style=" vertical-align:middle" ng-bind="days"></td>
<td width="100" align="center" style="padding:0px;" ng-repeat="hour in hours" >
<table style="margin:0px; padding:0px; width:100%">
<tr>
<td>
<select id="coy" name="coy" class="form-control" ng-model="subname">
<option value="">Select Course</option>
<option value="A">Theory1</option>
<option value="B">Theory2</option>
<option value="C">Theory3</option>
<option value="D">Theory4</option>
</select>
</td>
</tr>
<tr>
<td>
<select id="coy" name="coy" class="form-control" ng-model="facname" ng-change="readData();">
<option value="">Select Faculty</option>
<option value="A">Faculty1</option>
<option value="B">Faculty2</option>
<option value="C">Faculty3</option>
<option value="D">Faculty4</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
script.js
var myApp = angular.module('myApp', []);
myApp.controller('tableCtrl', ['$scope',
function($scope) {
$scope.noOfDays = [];
$scope.days = {
'0': "Monday",
'1': 'Tuesday',
'2': 'Wednesday',
'3': 'Thursday',
'4': 'Friday'
}
$scope.hours = [
'9AM :: 10AM',
'10AM :: 11AM',
'11:15AM :: 12:15PM',
'12:15PM :: 01:15PM',
'02PM :: 03PM',
'03PM :: 04PM',
'04PM :: 05PM'
]
for (var i = 0; i < 5; i++) {
$scope.noOfDays.push($scope.days[i]);
}
$scope.readData=function(){
alert($scope.subname.value,$scope.facname.value);
}
}]);
Upon triggering the ng-change event, the aforementioned error occurs. The objective is to store the selected course data and faculty name in a JSON variable based on day and time. Feel free to explore this plunker example and assist me in resolving this issue.