title: Angularjs Check Array before Push with NG-Disabled
body: <p>Each dress is assigned an ID, the dress ID can be found within the <code>$StateParams</code> function and the page URL - e.g #/dresses/21.</p>
  
  <p>When the user clicks the Heart (Like) or Broken Heart (Dislike) button the dress ID is placed within the localstorage Heart/Broken Heart array - see below.</p>
  
  <p>Also, when either button has been clicked the button disables itself, preventing multiple dress ID's being pushed! This can be reverted by clicking the opersit button.</p>
  
  <p><strong>The problem!</strong><br/>
  I can't figure out how to prevent submits the same dress ID after refreshing the page - I tried searching the array before pushing the dress ID but this didn't work. Also, I'm able to prevent double dress ID's from being submitted by preventing double clicks, but if I refresh the page the button is able to push dress ID's to the array although it already has the dress ID present! </p>
  
  <p>Any guidance would help massively!<br/>
  Thank you.</p>
  
  <p><strong>DESIGN:</strong><BR/>
  <a href="https://i.stack.imgur.com/sQFUf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sQFUf.png" alt="enter image description here"></a><br/>
  <strong>HTML:</strong></p>
  
  <pre><code>&lt;ul class="railcontrols"&gt;
    &lt;li&gt;
      &lt;md-button aria-label="" class="md-fab md-mini" ng-click="heart()" ng-dblclick="return false;" ng-disabled="heartflag"&gt;
        &lt;md-icon md-svg-src="svg/heart.svg"&gt;&lt;/md-icon&gt;
      &lt;/md-button&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;md-button aria-label="" class="md-fab md-mini" ng-click="brokenheart()" ng-dblclick="return false;" ng-disabled="brokenheartflag"&gt;
        &lt;md-icon md-svg-src="svg/brokenheart.svg"&gt;&lt;/md-icon&gt;
      &lt;/md-button&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p><strong>CONTROLLER:</strong></p>
  
  <pre><code>   fittingApp.controller('railsCtrl', ['$scope', '$localStorage', '$stateParams','$filter', function($scope, $localStorage, $stateParams, $filter) {
        $scope.$storage = $localStorage;
        var dressID = $stateParams.id;
        if ($scope.$storage.userLoveList === undefined) {
          var getUserID = $scope.$storage.profileData.userID;
          $scope.$storage.userLoveList = ({
            'userID': getUserID,
            'heart': [],
            'brokenheart': []
          });
        }
        $scope.heartflag = false;
        $scope.heart = function() {
          $scope.heartflag = true;
          $scope.brokenheartflag = false;
          // Push Heart
          $scope.$storage.userLoveList.heart.push({'dressID': dressID});
          // Remove BrokenHeart
          $scope.$storage.userLoveList.brokenheart = $filter('filter')($scope.$storage.userLoveList.brokenheart, {dressID: '!'+dressID});
        };
        $scope.brokenheartflag = false;
        $scope.brokenheart = function() {
          $scope.brokenheartflag = true;
          $scope.heartflag = false;
          // Push Broken Heart
          $scope.$storage.userLoveList.brokenheart.push({'dressID': dressID});
          // Remove Heart
          $scope.$storage.userLoveList.heart = $filter('filter')($scope.$storage.userLoveList.heart, {dressID: '!'+dressID});
        };
      }]);
  </code></pre>
  
  <p><strong>OUTPUT {{$storage | json}}</strong></p>
  
  <pre><code>{
    "userLoveList": {
      "userID": "1",
      "heart": [
        {
          "dressID": "21",
          "dressID": "21", // Prevent Duplicates
          "dressID": "19"
        }
      ],
      "brokenheart": [
       {
          "dressID": "10"
       }
      ]
    }
  }
  </code></pre>