我从javascript触发角度函数并尝试重复div。无法找到索引和从javascript返回的数据作为对象。
var app = angular.module('game',[]);
app.controller('myCtrl', function($scope) {
var json = [];
$scope.setlobbyData = function(obj){
$scope.json = obj;
$scope.lobbyData = json;
};
});
HTML
<div ng-controller="myCtrl">
<div ng-repeat="i in lobbyData">some data</div>
</div>
JS
var ssr = {
"0": {
"tradeSpread": 0,
"minBuyIn": 10,
"minPlayers": 2,
},
"1": {
"tradeSpread": 0,
"minBuyIn": 10,
"minPlayers": 2,
}
};
angular.element($("#foreignExchangeMain")).scope().setlobbyData(ssr);
答案 0 :(得分:0)
尝试使用ng-if
,这将反映在控制器中的集合更新时的视图:
<div ng-repeat="i in lobbyData" ng-if="lobbyData">some data</div>
答案 1 :(得分:0)
我使用$ apply函数来更新anugular并且事情得到了更新
var scope = angular.element($("#foreignExchangeMain")).scope();
scope.$apply(function(){
scope.json = ssr;
scope.setlobbyData(ssr)
});