title: AngularJS ng-class check if nested key/value pair exists and then add value as class
body: <p>So, I have this nested array which I can't modify the structure of. I want to check if a key/value pair exists and if it does, add a corresponding class to the element in question.</p>
  
  <p>I have been trying to use a variation of the expression:</p>
  
  <pre><code>ng-class="{ 'active' : data.indexOf('"name":"john"') &gt;= 0 }"
  </code></pre>
  
  <p>However my expression is a bit more complicated and I'm afraid it's too much to use just like that. There's also the problem of using more than two level nested quotes.</p>
  
  <p>Here's a fiddle using an array with a similar structure to what I'm working with:</p>
  
  <p><a href="http://jsfiddle.net/5tvmL2Lg/2/" rel="nofollow">http://jsfiddle.net/5tvmL2Lg/2/</a></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;body ng-app="myModule"&gt;
  &lt;div ng-controller="myController"&gt;
    &lt;div ng-repeat="hero in heroes"&gt;
      &lt;div ng-class="{ 'weight-\'hero.stats.indexOf('\'type\':\'weight\'').value\'' : hero.stats.indexOf('\'type\':\'weight\'') &gt;= 0 }"&gt;
              hello
       &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>var myModule = angular.module('myModule', []);
  
  myModule.controller('myController', ['$scope',  function($scope) {
  
      $scope.heroes = [{
        "firstname" : "clark",
        "lastname" : "kent",
          "stats" : [
          {
          "type" : "height",
          "value" : "6'2"
          },
          {
          "type" : "weight",
          "value" : 220
          },
          {
          "type" : "hair",
          "value" : "brown"
          }
        ]},
        {
        "firstname" : "bruce",
        "lastname" : "wayne",
          "stats" : [
          {
          "type" : "height",
          "value" : "6'1"
          },
          {
          "type" : "hair",
          "value" : "black"
          }
        ]},
        {
        "firstname" : "peter",
        "lastname" : "parker",
          "stats" : [
          {
          "type" : "height",
          "value" : "5'11"
          },
          {
          "type" : "weight",
          "value" : 180
          },
          {
          "type" : "hair",
          "value" : "auburn"
          }
        ]}];
  
  }]);
  </code></pre>
  
  <p>In the end the goal would be to add a class named for example "weight-220" for the "clark kent" div, no class for the "bruce wayne" div, and "weight-180" for the peter parker div.</p>
  
  <p>I know my problem is convoluted but any help would be greatly appreciated... :)</p>