1. How to create a select box using ng-option?

To create a drop-down list you should use ng-option directive. ng-option allow the selected value to object.

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/
ajax/libs/angularjs/1.4.5/angular.min.js"></script>
</head>
<body>
<div ng-app="myFirstApp" ng-controller="myController">
<select ng-model="selected" ng-options="y for y in names">
</select>
</div>
<script>
var myFirstApp= angular.module('myFirstApp', []);
myFirstApp.controller('myController', function($scope) {
$scope.names = ["Html","Css","Jquery"];
});
</script>
</body>
</html>

 

2. How to create a select box using ng-repeat?

We can use ng-repeat for drop down list .The drop-down made from ng-repeat is a string.

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/
ajax/libs/angularjs/1.4.5/angular.min.js"></script>
</head>
<body>
<div ng-app="myFirstApp" ng-controller="myController">
<select>
<option ng-repeat=" y in names">{{y}}</option>
</select>
</div>
<script>
var myFirstApp= angular.module('myFirstApp', []);
myFirstApp.controller('myController', function($scope) {
$scope.names = ["Html","Css","Jquery"];
});
</script>
</body>
</html>