I have to pass a bunch of inputs and outputs between two Angular controllers and I've come up with a way to do it using $broadcast.  I'm using an if statement to make sure the inputs match the outputs, but there must be an easier way.app.controller('Ctrl2', ['$scope', '$rootScope', function($scope, $rootScope) {  var myArray = [$scope.input1, $scope.input2];  $scope.textChange = function(whichChange) {    if (whichChange == 1) {      $rootScope.$broadcast('textChanged', $scope.input1, 1);    } else if (whichChange == 2) {      $rootScope.$broadcast('textChanged', $scope.input2, 2);    } //else if, else if, else if, etc...  };}]);But seems there should be a way I can replace that if statement with a single line, something like:$rootScope.$broadcast('textChanged', $scope.relevantInput, relevantOutput);Working Plunkr hereSame question applies to the case statement in controller Ctrl1, but I figure answering the question for one controller would answer it for the other.Also: while comments on whether this is the best way to do this in Angular are certainly welcome my question is more about avoiding if/switch/eval.
Passing variables by values without the dreaded if/switch/eval
javascript;angular.js
The first change I would suggest when using a lot of ifs is to put things in a map. This is assuming you know what values are expecting from whichChange:app.controller('Ctrl2', ['$scope', '$rootScope', function($scope, $rootScope) {  var inputById = {     1: $scope.input1,     2: $scope.input2  };  $scope.textChange = function(whichChange) {    var input = inputById[whichChange.toString()];    $rootScope.$broadcast('textChanged', input, whichChange);  };}]);