Javascript object creation on the fly
create objects on the fly with angularjs
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:
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++;
};
});
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.
When I run the code, well, the Angular breaks completely. If I comment out this section, however:
$scope.m2Info=[{
name:holdBuilding[c].name;
link:holdBuilding[c].link;
}];
Then the code runs and I am able to see that the alert does correctly alert the names. It just doesn't like the object building part. What am I doing wrong?
The error that I am getting when the Angular breaks is:
SyntaxError: missing } after property list
for line:
name:holdBuilding[c].name;
name:holdBuilding[c].name;. Sorry I forget to check that sometimes, still don't make sense to me.$scope.m1Special.Buildingsthat have thelocNorthern?