0

I am adding data to an array dynamically and trying to duplicate divs using ng-repeat.

If the data were added initially it renders properly, but not if we add data dynamically later.

angular

var app = angular.module('game',[]);
  app.controller('myCtrl', function($scope) {

  var json = [];
  $scope.setlobbyData = function(obj){
      $scope.json = obj;
      $scope.lobbyData = $scope.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);
Divya MV
  • 2,001
  • 2
  • 29
  • 54
ganesh vembu
  • 31
  • 1
  • 6

3 Answers3

0

I think the solution could be to call the

$scope.$apply();

See here: How can I tell AngularJS to "refresh"

Community
  • 1
  • 1
Blasfemizer
  • 146
  • 1
  • 8
0

Please refer this post for updating scope data from outside angular:

AngularJS access scope from outside js function

Community
  • 1
  • 1
Icycool
  • 6,724
  • 1
  • 21
  • 31
0

used $apply to refresh

 var scope = angular.element($("#foreignExchangeMain")).scope();
        scope.$apply(function(){
            scope.json = ssr;
            scope.setlobbyData(ssr)

        });
ganesh vembu
  • 31
  • 1
  • 6