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,021
  • 3
  • 31
  • 55
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
  • 156
  • 1
  • 9
0

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

AngularJS access scope from outside js function

Community
  • 1
  • 1
Icycool
  • 7,099
  • 1
  • 25
  • 33
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