Kaushi
Kaushi

Reputation: 198

Populating Combo box in AngularJS

controller.js

$scope.buildings={};

for (var i=0;i<$scope.buildingObj.length;i++){
        $scope.buildings.building=$scope.buildingObj[i].building;
        console.log($scope.buildings.building);
}

In console am able to print $scope.buildings.building. Now I want to populate $scope.buildings in a combobox.

EDIT

$scope.buildings gives

[Object, Object, Object]

$scope.buildings.building gives as below

Tidel
Ascendas
Sun-Tech

How can I do this? Am new to AngularJS. pls help me get through this.

Thanks in advance.

Upvotes: 0

Views: 64

Answers (2)

Coder John
Coder John

Reputation: 786

 <select>
    <option value="">--Select--</option>
    <option data-ng-repeat="l in buildings" value="{{l}}">{{l.building}}</option>

  </select>

Where your display will contain building name and value would be object which you could use on server side, or it could be l.building only if you directly want building name as value of selected option

Here is the Plunker: https://plnkr.co/edit/tInZEPLXokb9NkqGk2so?p=preview

Upvotes: 1

Kumar Gaurav
Kumar Gaurav

Reputation: 21

You could have a autocomplete textbox that will have textbox for the input and dropdownlist for search reference.

Below is the link : http://csharpimp.blogspot.in/2016/03/angular-material-auto-complete.html

Upvotes: 0

Related Questions