Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have code that populates then dropdownlist and the javascript variable that gets the last item in the list. Now all I want to do is select that last item as the default .What am I missing ?

<div class="row">
<div>
    <select ng-init="lastItem" ng-model="congressFilter" ng-options="cc.congressLongName for cc in ccList"></select>
</div>
<div class="grid-style" data-ng-grid="userGrid">
</div>

   ccResource.query(function (data) {
    $scope.ccList.length = 0;
    angular.forEach(data, function (ccData) {
        $scope.ccList.push(ccData);
    })

    //Set default value for dropdownlist?
    $scope.lastItem = $scope.ccList[$scope.ccList.length - 1];
});
share|improve this question
1  
Shouldn't it be ng-model="lastItem"? –  elclanrs Nov 11 '13 at 22:13
add comment

1 Answer

up vote 1 down vote accepted

You simply need to asign a value to congressFilter in your controller.

 $scope.congressFilter = 'someVal';

It depends a little on how your data looks however.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.