Mss iOS
Mss iOS

Reputation: 157

dynamic dropdown in angular js or ionic

$scope.AllCities = window.localStorage.getItem['all_cities'];
<div class="row">
      <div class="col">
        <div class="select-child" ng-options="citie.name for citie in AllCities"
		ng-model="data.city">
          <label>Select Child</label>
          <select class="form-control">
            
<option value="" disabled selected style="display: none;">Please Select City</option>
            
          </select>
        </div>
      </div>
    </div>

I have tried to create a dynamic dropdown but it show undefined here is my code

Upvotes: 1

Views: 616

Answers (1)

Anurag Pandey
Anurag Pandey

Reputation: 744

Dynamic category list show.

        <div class="label_EventDetail" align="left">Category</div>
            <select class="ion-input-select" ng-options="category.name for category in categorys" ng-model="selectedcategory" ng-change="callFunction(selectedcategory)">
                <option value="">Select Category</option>
            </select>
        </div>

and $scope variable like that

$scope.categorys = [{
            "id": 1,
            "name": "A",
            "select": true
        }, {
            "id": 2,
            "name": "B",
            "select": true
        }, {
            "id": 3,
            "name": "C",
            "select": true
        }, {
            "id": 4,
            "name": "D",
            "select": true
        }, {
            "id": 5,
            "name": "E",
            "select": true
        }, {
            "id": 6,
            "name": "F",
            "select": true
        }, {
            "id": 0,
            "name": "G",
            "select": true
        }];

// and call method is

    $scope.callFunction = function(data) {
        console.log(data);
      //you selected any data from list show in console.
    }

the above code when i select any from list ng-change event is called

ng-change="callFunction(selectedcategory)"

and callFunction is not necessary(its depend on use).

and you get selected data from selectedcategory variable.

Upvotes: 3

Related Questions