Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

AngularJS Select

AngularJS enables you to generate dropdown lists from items in an array or an object.

Creating a Select Box Using ng-options

To create a dropdown list based on an object or an array in AngularJS, you should utilize the ng-options directive.

Example

<div ng-app=”myApp” ng-controller=”myCtrl”>

<select ng-model=”selectedName” ng-options=”x for x in names”>
</select>

</div>

<script>

var app = angular.module(‘myApp’, []);
app.controller(‘myCtrl’function($scope) {
  $scope.names = [“Emil”“Tobias”“Linus”];
});
</script>