title: How can I create an object on the fly with AngularJS using variables?
body: <p><a href="https://stackoverflow.com/questions/2016124/javascript-object-creation-on-the-fly">Javascript object creation on the fly</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16577520/create-objects-on-the-fly-with-angularjs">create objects on the fly with angularjs</a></p>
  
  <p>Ok so yes, I can create objects on the fly. But I am having a hard time implementing this into my own code. Here is what I have:</p>
  
  <pre><code>var holdBuilding = $scope.m1Special.Buildings;
  var c = 0;
  $scope.m2Info = {};
  
  angular.forEach(holdBuilding,function(){
      if($scope.m1Special.Buildings[c].loc=="Northern"){
          alert(holdBuilding[c].name);
          $scope.m2Info=[{
              name:holdBuilding[c].name;
              link:holdBuilding[c].link;
          }];
          c++;
      };
  });
  </code></pre>
  
  <p>My code seems to resemble the 1st link more than the 2nd, but the 2nd is using Angular. I think he is doing something different than me though. Or maybe I am just approaching this wrong.</p>
  
  <p>When I run the code, well, the Angular breaks completely. If I comment out this section, however:</p>
  
  <pre><code>    $scope.m2Info=[{
          name:holdBuilding[c].name;
          link:holdBuilding[c].link;
      }];
  </code></pre>
  
  <p>Then the code runs and I am able to see that the alert does correctly alert the <em>names</em>. It just doesn't like the object building part. What am I doing wrong?</p>
  
  <p>The error that I am getting when the Angular breaks is:</p>
  
  <blockquote>
    <p>SyntaxError: missing } after property list</p>
  </blockquote>
  
  <p>for line:</p>
  
  <pre><code>name:holdBuilding[c].name;
  </code></pre>