angularjs - fill select list conditionally in Angular -
i have select list should filled conditionally .
here condtion :
function data
function getdocumenttypelist() { baseinfoservice.getdocumenttypelist().then(function (data) { $scope.documenttypelist = data; $scope.requestauthorization.documenttype = 0 $scope.conditionallabel(); debugger; }); } //////////////////////////// function getspeciallist() { baseinfoservice.getspeciallist().then(function (data) { $scope.speciallist = data; debugger; }); }
there select list define 1 should shown .
if value ===1 ng-option fill people
if value === 2 ng-option fill person
[fiddle]1
thanks
assumption: shape of 2 lists similar.
you can have scope function source , in function if or switch statement figure out source use.
something this:
(function() { 'use strict'; angular.module('myapp', []); angular.module('myapp') .controller('myctrl', myctrl); myctrl.$inject = ['$log']; function myctrl($log) { var self = this; var ducks = [ { name: 'donald' }, { name: 'daisy' } ]; var mice = [ { name: 'mickey' }, { name: 'minnie' } ]; self.listtype = 2; //change 1 ducks, 2 or else mice self.selectedthing = null; self.getlistoptions = function() { switch(self.listtype) { case '1': return ducks; case '2': default: return mice; } } } }());
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myapp" ng-controller="myctrl vm"> <label for="radtype1"><input type="radio" name="radtype" id="radtype1" ng-model="vm.listtype" value="1">ducks</label> <label for="radtype2"><input type="radio" name="radtype" id="radtype2" ng-model="vm.listtype" value="2">mice</label> <br> <select ng-options="o.name o in vm.getlistoptions()" ng-model="vm.selectedthing"> </select> </div>
Comments
Post a Comment