Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Changing the value of a dropdown when the value of a number box changes in AngularJS

angular.module('myApp', [])
  .controller('myCtrl', ['$scope', '$http', function($scope, $http) {
    $scope.pizzaBox = {
      numSlices: 5,
      pizzaSizes: ["Small", "Large"],
      selectedPizzaSize: "Small"
    };

    $scope.onNumSlicesChanged = function() {
      if ($scope.pizzaBox.numSlices <= 8) {
        $scope.pizzaBox.selectedPizzaSize = "Small";
      } else {
        $scope.pizzaBox.selectedPizzaSize = "Large";
      }
    };
  }]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <input name="nameForNumberField" ng-model="pizzaBox.numSlices" type="number" ng-change="onNumSlicesChanged()" />
  <select id="nameForDropdown" data-ng-model="pizzaBox.selectedPizzaSize" ng-options="x for x in pizzaBox.pizzaSizes"></select>
</div>
Comment

PREVIOUS NEXT
Code Example
Javascript :: angularjs Uncaught ReferenceError: myFunction is not defined at HTMLInputElement.onkeyup 
Javascript :: angularjs No alignment and missing item in a vertical menu 
Javascript :: angularjs promise .then() to run sequentially inside a for loop 
Javascript :: how to replace img url using jquery on mobile screen 
Javascript :: Angularjs $on called twice 
Javascript :: Prevent the wiping of an Array after routing Angular.js 
Javascript :: AngularJS disable default form submit hook 
Javascript :: Presenting backend data using AngularJS/AJAX in MVC VIEW 
Javascript :: how to set a condition so that between the first and second mouse clicks there was a delay not 500mls 
Javascript :: Edit parameter in variable with increment/decrement box and save it 
Javascript :: In React Native / Expo, is there any way to save a specific part of an image 
Javascript :: How to check the increase/decrease of letter input in pasting clipboard in jQuery 
Javascript :: get lat long from address google api 
Javascript :: sending api with limited fields in express 
Javascript :: Transfer file to server using rsync 
Javascript :: nextjs app wdyr 
Javascript :: mustache tutorial javascript 
Javascript :: input json decode 
Javascript :: Creating A Promise With JSON 
Javascript :: What is an array? Is it static or dynamic in Javascript 
Javascript :: Make Floating label TextInput with password show/hide in react native 
Javascript :: photoshop Change image size JavaScript 
Javascript :: repeater jquery 
Javascript :: save to text or html file very good 
Javascript :: returning the outliers javascript array 
Javascript :: todo app html css javascript 
Javascript :: var countdown = function(num) {} 
Javascript :: top of stack javascript 
Javascript :: React Futures - Server Components 
Javascript :: filter function in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =