title: If using AngularJS's directive as an object, then how do you implement an instance method?
body: <p>It is said that we can consider directive as an object, such as implementing a "count" widget on the web page.  Clicking on the left label will decrement the count, while clicking on the right will increment the count.</p>
  
  <p>If so, can we implement an instance method for it, to do a <code>getCount()</code>?</p>
  
  <p>Example:</p>
  
  <p><a href="https://jsfiddle.net/htcvuer1/3/" rel="nofollow">https://jsfiddle.net/htcvuer1/3/</a></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div ng-app="myApp"&gt;
    &lt;count value="1"&gt;&lt;/count&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>angular.module("myApp", [])
    .directive("count", function() {
      return {
  
        template: "click me: &lt;span ng-click='dec()'&gt;decrement&lt;/span&gt; &lt;span class='the-count'&gt;{{value}}&lt;/span&gt; &lt;span ng-click='inc()'&gt;increment&lt;/span&gt;",
  
        scope: {
          value: "="
        },
  
        link: function(scope, el, attrs) {
          scope.dec = function() {
            scope.value--;
          };
          scope.inc = function() {
            scope.value++;
          }
        }
  
      }
    });
  </code></pre>