SoFunction
Updated on 2025-04-11

Angularjs sets the value method of another select based on the value of a select

html:

<div ng-controller="mySelectController">
<select ng-model="myField" ng-options=" for Field in names" 
ng-change="mySelectControllerChange()">
<option value=''>{{'' | translate}}</option>
</select>
</div>
 <div ng-controller="myRelationController">
<select ng-model="myRelation" ng-options=" for relation in relationList" >
<option value=''>{{'' | translate}}</option>
</select>
</div>

js:

var mySelectController=['$scope', '$http', '$rootScope', function($scope, $http, $rootScope) {
 
 //The method of $http can be get/delete/head/jsonp/post/put //$http service fast get request //alert('root=='+);//corresponding to /activiti-explorer/service $http({
 method:'PUT',
 url: +'/getFormFieldList'
 })
 .success(
 function(data,status,headers,config){
 //Load successfully   $=data;
 })
 .error(
 
 function(data,status,headers,config){
 //Processing error //do nothing
 }
 );
 //change
 $=function(){
 var app=('activitiModeler',[]);
 if($!=null &amp;&amp; $!=''){
 //There is optionGroup ('if');
 $ = [{id:0,name:'equal'},{id:1,name:'Not equal'},{id:2,name:'Include'}];
 }else{
 //No optionGroup ('else');
 $ = [{id:0,name:'equal'},{id:3,name:'Greater than'},{id:4,name:'Little than'},{id:5,name:'Little than or equal to'},{id:6,name:'Greater than or equal to'},{id:2,name:'Include'}];
 }
 
 }
 
}
];

//AngularJS $emit $broadcast $on

//change
 $=function(){
 var data=null;
 if(null==$){
 data={
  pa:'',
  pb:''
 };
 }else{
 data={
  pa:$,
  pb:$
 };
 }
 $scope.$emit('to_myParentController_on_myColumnSelectModel_change',data);
 }
 
/*myParentController*/
('activitiModeler').controller('myParentController',['$rootScope', '$scope', '$http', '$timeout','$window', function ($rootScope, $scope, $http, $timeout,$window) {
 //Select the field drop-down list and trigger the relationship character drop-down $scope.$on('to_myParentController_on_myColumnSelectModel_change',function(event,data){
 $scope.$broadcast('to_myRelationController_on_myColumnSelectModel_change',data);
 });
 
 
}]);
 
/*Relational symbol*/
('activitiModeler').controller('myRelationController',['$rootScope', '$scope', '$http', '$timeout','$window', function ($rootScope, $scope, $http, $timeout,$window) {
 $=true;
 $=true;//Add a gray background //Receive Events-Drag the drop-down according to the field $scope.$on('to_myRelationController_on_myColumnSelectModel_change',function(event,data){
 if(!=''){
 $=false;
 $=false;// Remove the gray background if(!=null &amp;&amp; !=''){
 //There is optionGroup $ = [{id:0,name:'equal'},{id:1,name:'Not equal'},{id:2,name:'Include'}];
 }else{
 //No optionGroup $ = [{id:0,name:'equal'},{id:3,name:'Greater than'},{id:4,name:'Little than'},{id:5,name:'Little than or equal to'},{id:6,name:'Greater than or equal to'},{id:2,name:'Include'}];
 }
 }else{
 $=null;
 $=true;
 $=true;//Add a gray background }
 
 });
 
}]);

The above article Angularjs is the method of setting another select value based on the value of one select. It is all the content I share with you. I hope you can give you a reference and I hope you can support me more.