Home > DeveloperSection > Forums > create ng Options with Group By
Ankit Singh

Total Post:341

Points:2389
Posted on    February-23-2016 10:09 PM

 Angular JS Angular JS 
Ratings:


 1 Reply(s)
 222  View(s)
Rate this:
We want to create ng options with group by in angular JS .How to do this please help me.


aditya kumar Patel

Total Post:244

Points:1736
Posted on    February-23-2016 10:11 PM

@{

Layout = null;

}

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width" />

<script src="~/Scripts/jquery-1.9.1.js"></script>

<script src="~/Scripts/angular.js"></script>

<title>Forum</title>

<script>

var app = angular.module('myApp', []);

app.controller('MyCtrl', function ($scope) {

$scope.rows = [

{

"group": "Uttar Pradesh",

"displayName": "Allahabad",

"modelName": "Allahabad"

},

{

"group": "Uttar Pradesh",

"displayName": "Phulpur",

"modelName": "Phulpur"

},

{

"group": "Maharashtra",

"displayName": "Thane",

"modelName": "Thane"

},

{

"group": "Maharashtra",

"displayName": "Bandra",

"modelName": "Bandra"

}

,

{

"group": "Maharashtra",

"displayName": "Kurla",

"modelName": "Kurla"

}

]

})

</script>

</head>

<body ng-app="myApp" ng-controller="MyCtrl">

<div>

Select City :<select ng-model="row"

ng-options="row.modelName as row.displayName group by row.group for row in rows">

</select>

</div>

</body>

</html>


Don't want to miss updates? Please click the below button!

Follow MindStick