Javascript object creation on the fly如何使用變量隨時使用AngularJS創建對象?
create objects on the fly with angularjs
好了,所以,是的,我可以動態創建對象。但是我很難將其實現到我自己的代碼中。這裏是我有:
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++;
};
});
我的代碼似乎像第一個鏈接超過第二,但第二個使用Angular。儘管如此,我認爲他正在做一些與我不同的事情。或者,也許我正在接近這個錯誤。
當我運行代碼時,Angular完全打破了。如果我註釋掉不過本節,:
$scope.m2Info=[{
name:holdBuilding[c].name;
link:holdBuilding[c].link;
}];
然後代碼運行,我能夠看到該警示不正確地提醒名。它只是不喜歡對象構建部分。我究竟做錯了什麼?
,我得到當角斷裂是錯誤:
SyntaxError: missing } after property list
線路:
name:holdBuilding[c].name;
定義「完全中斷」。 –
當Angular完全斷開時,它會顯示頁面上的所有插值。任何來自Angular控制器的內容都不會顯示。 – Christine268
而在控制檯中的錯誤是? –