I am facing a challenge in populating select(option) element inside a template html file from the controller. Although I have managed to do it successfully, I am unable to set a default value to avoid the initial empty option.
Here is a snippet from the template.html file:
...
<select name="drill_down" id="drill_down" ng-model="drill_down"
ng-options="item.value for item in items"></select>
...
And here is a snippet from the controller.js file:
(function () {
'use strict';
var app = angular.module('appname', []);
app.config(function($stateProvider) {
$stateProvider
.state('appname', {
url: '/appname',
templateUrl: '/appname/template.html',
controller: 'AppCtrl'
});
});
app.controller('AppCtrl', AppCtrl);
function AppCtrl($scope, MyService) {
$scope.college_majors_full = [];
$scope.job_title_functions = [];
MyService.getData().then(function(rows) {
$scope.items = rows; // this works - populates select options
$scope.drill_down = $scope.items[0].value; // this doesn't work
});
...
If anyone has any suggestions or solutions, I would greatly appreciate your help. Thank you.