title: Angular function pass scope variable by reference
body: <h2>Question</h2>
  <p>Is it possible to pass a scope variable (specifically an array) <em>by reference</em> to a function called using ng-click, and manipulate the value of said variable?</p>
  <p><strong>Update:</strong>
  To be more explicit, my goal here is to avoid having to access $scope in <code>$scope.app.onItemClick</code>.</p>
  <h2>Example</h2>
  <p>Javascript:</p>
  <pre><code>(function() {
      angular.module('test', [])
      
      angular.module('test').controller('test',['$scope', function ($scope) {
        $scope.app = {};
        
        $scope.app.primarySet = [
          'test1',
          'test2',
          'test3'
        ]
        
        $scope.app.workingSet = [
          'test4',
          'test5',
          'test6'
        ]
        
        /*
         * Attempts to assign $scope.app.primarySet to $scope.app.workingSet using references to those two values.
         */
        $scope.app.onItemClick = function (primarySet, workingSet) {
          primarySet = workingSet
        }
      }])
    })()
  </code></pre>
  <p>Relevant HTML:</p>
  <pre><code>&lt;button type=&quot;button&quot; ng-click=&quot;app.onItemClick(app.primarySet, app.workingSet)&quot;&gt;Update Primary Set&lt;/button&gt;
  </code></pre>
  <p><em>Please see <a href="https://plnkr.co/edit/HroqJmSjFcNIJ00OZvU7" rel="nofollow noreferrer">this Plunker</a> for this code in more context.</em></p>
  <p>My expectation for this code is that <code>$scope.app.primarySet</code> would be set to <code>$scope.app.workingSet</code> when the button is pressed. Unfortunately, this is not the case. While debugging, in the scope of the function, <code>primarySet</code> is assigned to <code>workingSet</code>. However <code>$scope.app.primarySet</code> is not.</p>
  <h2>Motivation</h2>
  <p>My motivation for this is rooted in <a href="https://stackoverflow.com/a/19195814/4826488">this SO reply</a>. I share the belief that it will be easier to test methods that manipulate scope if I am not referencing it directly. I also find this more straightforward than having a function manipulate the scope directly.</p>
  <h2>Previous Research</h2>
  <p>The only resource that I have come across relating to this is <a href="https://stackoverflow.com/questions/28235514/pass-scope-variable-to-function-by-reference">this SO question</a>. While this question comes close, it is different in that the parameter in question is a string, which, if I understand correctly, cannot be modified <em>as a reference could be expected to</em>.</p>