0

I have a snippet of js that causes an update in the webpage when $Scope.$apply is called. Specifically, it causes the data in an angular-ui-grid to update.

An example:

The code is triggered by this HTML:

<div google-chart chart = "chartObject" style = "height:600px; width:100%;" agc-on-select="selectHandler(selectedItem)" ng-if="chartvisible"></div>

This Creates a UI grid:

$scope.gridOptions = gridService.getGrid([25, 50, 75], 25, ['username','startTime']);
 

    $scope.gridOptions.data = post;
     $scope.$apply();

Where the variable 'Post' is something like:

[
   {
       "challenge": "asdfrew2",
       "id": 1,
       "startTime": "start time 1",
       "successfullyCompleted": false,
       "username": "JamieFalter"
   },
   {
       "challenge": "454454y",
       "id": 2,
       "startTime": "start time 2",
       "successfullyCompleted": false,
       "username": "Falter"
   }
]

Returns an error that looks like this:

TypeError: Converting circular structure to JSON

at na (angular.js:1121)
at angular.js:20566
at Object.fn (angular.js:12411)
at k.$digest (angular.js:12540)
at k.$apply (angular.js:12805)
at Object.<anonymous> (Controller.js:54)//Points to the Scope.Apply
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4)

Has anyone seen anything like this before? If so, how did you solve it?

Community
  • 1
  • 1
James Falter
  • 55
  • 1
  • 7
  • 1
    why are using `$apply` if you are already in `angular context`? – ram1993 Nov 01 '16 at 15:32
  • @ram1993 I'm using $apply to force it to run a new $digest cycle. Without it, the contents of the angular-ui-grid will not update. If you have an alternate suggestion to do this, it would be appreciated. – James Falter Nov 01 '16 at 15:37

0 Answers0