title: AngularJS Directive Two-Way Data Binding Not Working When Observing Boolean
body: <p>I have a two-way data binding that is not altering the value of the variable sent to the directive.</p>
  
  <p>My directive watches for a trigger and gives focus to the associates element (based on code found here at SO):</p>
  
  <pre><code>app.directive('focusMe', function ($timeout) {
    return {
      scope: {
        trigger: '=focusMe'
      },
      link: function (scope, element, attrs) {
        scope.$watch('trigger', function(value) {
          console.log("directive value: " + value);
          console.log("directive start: " + scope.trigger);
          if (value === true) {
            $timeout(function () {
              element[0].focus();
              scope.trigger = false;
              console.log("directive end: " + scope.trigger);
            });
          }
        });
      }
    }
  });
  </code></pre>
  
  <p>In the HTML I call it as follows:</p>
  
  <pre><code>&lt;input type="text" ng-model="item.value" focus-me="focusInput" /&gt;
  </code></pre>
  
  <p>When I trigger it for the first time, it works -- because the <code>focusInput</code> variable switches its value. But <code>focusInput</code> in the controllers scope (outside the directive) does not switch back to <code>false</code> when the directive completes.</p>
  
  <p>This switch back to <code>false</code> should happen when I call <code>scope.trigger = false</code>, assuming I understand what should be happening.</p>
  
  <p>What is missing that would cause the two-way binding to not push the value back to the variable passed into the directive?</p>
  
  <p><strong>UPDATE 01:</strong></p>
  
  <p>For posting the question I removed a small bit of code. The HTML actually looks like this:</p>
  
  <pre><code>&lt;input type="text" ng-model="item.value" focus-me="focusInput" ng-if="item.condition != 'matches' &amp;&amp; item.condition != 'does not match'" /&gt;
  </code></pre>
  
  <p>If the <code>input</code> fields hides and then is re-shown (based on the <code>ng-if</code>) the directive will properly give focus the first time <code>focusInput</code> changes. It will stop working again after that... unless the hide/show process is repeated.</p>