CREATE NG OPTIONS WITH GROUP BY

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 528  View(s)
Ratings:
Rate this:
We want to create ng options with group by in angular JS .How to do this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: create ng Options with Group By

    @{

    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!