Function of isolated scope gets called multiple times
<p>I wrote an angular code to implement Like and remove Like functionality. For this purpose I used a directive "like-directive" which takes three functions
1. upFn : code to be executed when liked
2. downFn: code to be executed when like removed
3. upvChk: function which checks whether it is liked or not. I started this with false</p>

<p>For some reason I cannot use a variable with ng-if. I have to use the upvChk function. But this function is getting called more than twice. It should be called only twice because I'm using ng-if twice.</p>

<p>Here is the codepen link <a href="http://codepen.io/puneet27/pen/jApJww/" rel="nofollow">http://codepen.io/puneet27/pen/jApJww/</a></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>angular.module('app',[])
  .controller('MainCtrl',['$scope',MainCtrl])
  .directive('likeDirective',[likeDirective]);
  
  function MainCtrl($scope){
    var mcl = this;
    mcl.checkUpvoted = checkUpvoted;
    mcl.upvote = upvote;
    mcl.downvote = downvote;
    
    function checkUpvoted(){
      alert("function to check whether liked or not");
      return mcl.upvoted;
    }
    function upvote(){
      alert('like completed');
      mcl.upvoted = true;
    }
    function downvote(){
      alert('dislike completed');
      mcl.upvoted = false;
    }
  }
  function likeDirective(){
    return {
      restrict: 'E',
      scope: {
        upFn:'&amp;upFn',
        downFn:'&amp;downFn',
        upvChk:'&amp;upvChk'
      },
      templateUrl: 'tpl.html'
    }
  }</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;


&lt;div ng-app="app"&gt;
  &lt;div ng-controller="MainCtrl as mc"&gt;
    &lt;like-directive up-fn="mc.upvote()" down-fn="mc.downvote()" upv-chk="mc.checkUpvoted()"&gt;&lt;/like-directive&gt;
  &lt;/div&gt;
  &lt;script type="text/ng-template" id="tpl.html"&gt;
    &lt;div&gt;&lt;span id="upvote" ng-if="!upvChk()" ng-click="upFn()"&gt;Like&lt;/span&gt;&lt;span id="upvoted" ng-if="upvChk()" ng-click="downFn()"&gt;Liked&lt;/span&gt;&lt;/div&gt;
  &lt;/script&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>