Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Display name instead ID modal dropdown in angularjs

angular.module('myApp', [])
  .controller('myCtrl', ['$scope', function($scope) {
    $scope.userInput = {
      state: {}
    };
    $scope.state = [{
      "name": "Califoria",
      "id": 1
    }, {
      "name": "Texas",
      "id": 2
    }]

    $scope.getCounties = function() {
      // $scope.userInput.state is updated autmatically with the ID
      console.log($scope.userInput)
      // the associated data can be found using 
      let state = $scope.state.find(s => s.id == $scope.userInput.state)
      $scope.selectedState = state.name; // for display

    }
  }]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <select ng-model="userInput.state" ng-change="getCounties()">
    <option ng-repeat="item in state" value="{{item.id}}">
      {{item.name}}
    </option>
  </select>

 <p> {{selectedState}} </p>
</div>
Comment

PREVIOUS NEXT
Code Example
Javascript :: Changing the value of a dropdown when the value of a number box changes in AngularJS 
Javascript :: How to append variable with anchor element href link in Angularjs 
Javascript :: angularjs Prevent from getting rendered 
Javascript :: angularjs Manipulate an element that is conditionally rendered 
Javascript :: directive with ng-if not rendering in Angular.js 
Javascript :: How to call keyup function on textbox for every dynamic generated form in Angular8 
Javascript :: Angularjs onchange datetime picker not working 
Javascript :: createaction ngrx example 
Javascript :: Angular Nx Nrwl - Cannot parse tsconfig.base.json: PropertyNameExpected in JSON when try to create a new lib 
Javascript :: React Native : Add a band of color in the background 
Javascript :: how to edit data retrieval using jsp 
Javascript :: Extract and convert from JSON by Regex 
Javascript :: reverse array without using another array 
Javascript :: JavaScript delete atray item 
Javascript :: error first callback in node js 
Javascript :: aws amplify react site is blank after updating react-router-dom 
Javascript :: read excel file npm 
Javascript :: Import Variable From Module In JavaScript 
Javascript :: Creating Multiple Methods From A List Of Words 
Javascript :: convert json date to java date 
Javascript :: how to add random color in chart in react j 
Javascript :: pass a react component as a prop from another component 
Javascript :: javascript complier 
Javascript :: Calculate sum of last column in dynamically added rows using javascript 
Javascript :: check if can go back react native 
Javascript :: how to check bot channel permissions 
Javascript :: leetcode solution problem 66 plus one 
Javascript :: adding number upto n , adding number, fastest number addding 
Javascript :: how to check if a div tag contains child 
Javascript :: how to receive form data in node js 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =