I need to populate select(option) element inside template html file from controller. I could do it successfully, but can't give default value(to avoid the first empty option)
template.html file
...
<select name="drill_down" id="drill_down" ng-model="drill_down"
ng-options="item.value for item in items"></select>
...
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
});
...
Any help? Thanks.