Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to create a drop-down box with a small description. When a item from the drop-down is select, the description box must give a description of it. So the problem I face is here I don't know how to link these two together properly as of now Im able to display the drop down with items but I failed in the link of description box, so please help me in linking the drop-down and description for each selection being made.

What I have tried:
Posted
Updated 26-Sep-16 19:07pm

try this

HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script>
        var app = angular.module('myapp', []);
        app.controller('myctrl', myfun);
        function myfun($scope) {
            $scope.description = '';
            $scope.selectedItem = 'select'
            $scope.items = [
                { value: "select", description: "" }, { value: "apple", description: "is a fruit" }, { value: "carrot", description: "is a vegtable" }, { value: "cashew", description: "is a nut" }
            ];
            $scope.changeItem = function () {

                var item = $scope.selectedItem;
                for (var i = 0; i < $scope.items.length; i++) {
                    if ($scope.items[i].value == item) {
                        $scope.description = $scope.items[i].description;
                        break;
                    }
                } 
            }

        }
    </script>

</head>
<body ng-controller="myctrl" ng-app="myapp">

    <select ng-model="selectedItem" ng-change="changeItem()">
        <option ng-repeat="x in items" value="{{x.value}}">{{x.value}}</option>
    </select>
    <span style="border:1px solid gray" id="desc">&nbsp;{{description}}&nbsp;</span>


</body>
</html>
 
Share this answer
 
Comments
Karthik_Mahalingam 27-Sep-16 0:41am    
something like ???
not clear, pls be more specific, post a screenshot.
<ion-list>
  <ion-item ng-repeat="item in items">
    Hello, {{item}}!
  </ion-item>
</ion-list>
 
Share this answer
 
Comments
Member 12747513 27-Sep-16 1:12am    
@Karthik Bangalore . sorry for the previous post , the code wasn't posted. I was talking about something I have posted as solution 2. Is it possible to use this so that I can perform the actions like add,delete and pop-up windows

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900