title: AngularJS - Get $scope variable from string
body: <p>So say I have a <code>$scope</code> variable defined like so:</p>
  
  <pre><code>$scope.data = {
      filter: {
          state: 'WA',
          country: 'US'
      }
  };
  </code></pre>
  
  <p>How do I access that in a separate service by string? e.g. <code>data.filter</code> in the context of the <code>$scope</code>.</p>
  
  <p>So say I have a service method like so:</p>
  
  <pre><code>function doSomething($scope, variableName) {
      // I want to access $scope[variableName] here??
  }
  </code></pre>
  
  <p>I would call it from the controller like so:</p>
  
  <pre><code>service.doSomething($scope, 'data.filter');
  </code></pre>