Max R. Max R. - 1 month ago 5
AngularJS Question

AngularJS ng-repeat Expression to JavaScript

I'm trying to read out data from my Database with AngularJS which is working fine, but I can't figure out, how to get Data out of ng-repeat to a JavaScript Object or something.

The data is now an expression, after the ng-repeat, right? I read something about a parser option but I couldnt understand how it works or even if this is what I needed.

<div ng-app="myApp" ng-controller="customersCtrl">


<table>
<tr ng-repeat="x in records">
<td>{{ x.Timestamp }}</td>
<td>{{ x.PT1 }}</td>
</tr>
</table>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost/tests/dataconn.php")
.then(function (response) {$scope.records = response.data.records;});
});

</script>


So what I need: the x.Timestamp and the x.PT# passed to JavaScript. :)

Kind regards,

Max

Edit: SORRY, forgot to add my code!

Answer

Create a global variable out of angular context then store in it.

for Ex :

<script> 
    var testData={};  // Global object
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
      $http.get("http://localhost/tests/dataconn.php")
      .then(function (response) {
       $scope.records = response.data.records;
       testData.records = $scope.records; // you can access this **testData** globally.
      });
   });
</script>
Comments