title: Load value from db on rendering directive template
body: <p>I am stuck in a doubt <br/>
  I have html :<br/></p>
  
  <pre><code>&lt;div ng-repeat="mydata in data" class="ng-scope ng-binding"&gt;
  
     &lt;p class="ng-binding"&gt;{{mydata.postdata}}&lt;/p&gt; 
     &lt;div my-rating rating-value="rating" data-cat="post" data-id="mydata.id" &gt;&lt;/div&gt;
  
     &lt;div ng-repeat="childData in mydata.personRelatedData"&gt;
            {{childData.personName}}  
            &lt;div my-rating rating-value="rating" data-cat="person" data-id="childData .id" &gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have a Directive : </p>
  
  <pre><code>myDirectives.directive('myRating', function () {
    return {
      restrict: 'A',
      template: '&lt;div&gt;&lt;ul&gt;' +
        '&lt;li ng-repeat="i in getNumber(myNumber)" ng-click="toggle($index)" id=$index&gt;' +
        '&lt;div ng-switch="switchPoint&lt;$index"&gt;'+
        '&lt;div ng-switch-when=true&gt;&lt;img ng-src="img/{{Unrated}}"&gt;&lt;/div&gt;'+
        '&lt;div ng-switch-when=false&gt;&lt;img ng-src="img/{{Rated}}"&gt;&lt;/div&gt;'+
        ' &lt;/div&gt;' +
        '&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;',
  
      scope: {
        ratingValue: '=',         
          dataCat: '=',  
          dataId: '=',  
        readonly: '@',
        onRatingSelected: '&amp;'     
      },
      link: function (scope, elem, attrs) {       
        scope.myNumber = 5;       
        scope.getNumber = function(num) {
              return new Array(num);   
        }     
  
        // if myId exists in array tab[], which is  an array consisting of rated datas' ids      
        if (tab.indexOf(scope.myId+"") != -1) {
        console.log("ID in DB !!!" + scope.dtId);          
    db.transaction(function (tx) {
          //get Rating value of ID dt.ID
      }              
        }
  
        scope.toggle= function(val) {
          scope.ratingValue = val + 1;          
          scope.onRatingSelected({rating: null});
          scope.switchPoint = val;                    
        } 
      }
    }
  }
  </code></pre>
  
  <p>Now what I am trying here is that on load of a rating template, i check whether the data with that ID exists in db, and if it does, then render that rating on load of the rating template. But this is not working.<br/></p>
  
  <p>Console Shows :</p>
  
  <pre><code>ID in DB !!! : ABC
  ID in DB !!! : DEF
  ID in DB !!! : GHI
  Setting Switch Point to 2
  Setting Switch Point to 5
  Setting Switch Point to 4
  </code></pre>
  
  <p>The result is that the rating templates that I have rated, on page load do get rated, but to the max value. While the unrated ones are fine. <br/></p>