title: Angular Js ng-init is not working properly inside ng-repeat while setting a variable
body: <p>I have a ng-repeat where i am checking a if condition and at the end of each repeation of loop i am setting a variable to a value from ng-repeat </p>
  
  <p>Here is my variable which i want to set inside the ng-repeat </p>
  
  <pre><code>$scope.prvSid = "";
  </code></pre>
  
  <p>Here is my ng-repeat code </p>
  
  <pre><code>&lt;ul class="chats" ng-repeat="chatData in chatboxData"&gt;
      &lt;li ng-class="{ 'out': chatData.sender_id == user_id , 'in': chatData.sender_id != user_id }"&gt;
           {{   prvSid }}
           {{   chatData.sender_id }}
          &lt;span ng-if=" prvSid != chatData.sender_id "&gt;
              &lt;img class="avatar" alt="" src="{{ url('default/img/user_default_logo.jpg') }}" /&gt;
          &lt;/span&gt;
          &lt;div class="message"&gt;
              &lt;span class="body"&gt; {{ chatData.message }} &lt;/span&gt;
          &lt;/div&gt;
          &lt;span ng-init="prvSid = chatData.sender_id"&gt;&lt;/span&gt;
          {{   prvSid }}
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>The problem which i am facing here is that whenever i print these values inside the ng-repeat  then prvSid  and chatData.sender_id is printing the same id the value of chatData.sender_id even for the first iteration and that's why this </p>
  
  <pre><code>&lt;span ng-if=" prvSid != chatData.sender_id "&gt;
  </code></pre>
  
  <p>condition is not working and my image is not displaying because for the first iteration the condition should be true because prvSid is <code>""</code> and chatData.sender_id has some id in it</p>
  
  <p>The purpose of this is to 
  Henry Zou the purpose is to not show profile picture for two or more messages submitted by same user (if the sender_id is same)Then dont display the profile image.When the new message comes from another sender which means sender_id is different then show the profile image</p>
  
  <p>at first the prvSid will be null so it will show the image because condition will not match at the end of each iteration i will set the prvSid to the current iteration sender_id to match this prv_id with sender_id in the next iteration </p>
  
  <p>i am also getting messages after two seconds and then i am adding the new records in the chatboxdata if they dont exist in it </p>
  
  <pre><code>$scope.getlasttwosecMsgs = function(user_id_chat,chat_id,user,chatboxData,is_new) {
        $http.get(url+'/getlasttwosecMsgs/'+chat_id).success(function(data){
          angular.forEach(data, function(value, key) {
            var exists = $scope.containsObject(value,chatboxData);
            if (!exists) {
              $scope.chatboxData.push(value);
              console.log($scope.chatboxData);
            };
          });
        });
      }
  $scope.containsObject = function(obj, list) {
          var i;
          for (i = 0; i &lt; list.length; i++) {
              if (angular.equals(list[i], obj)) {
                  return true;
              }
          }
  
          return false;
      };
  </code></pre>