0

I know it sounds like a repost but I still have to ask how I can do this in my project.

I have a class in PHP handling API-calls and receiving data. This received JSON data I would like to pass to Angular and present it in UI-Grid. Furthermore the page that I'm working with is in PHP and echoes the HTML for the Angular grid. How can I make it use the previously loaded data from the API?

I've seen many answers to other peoples very similar problems but haven't been able to make them work.

EDIT:

So inside the php I have:

<div ng-controller="DataController as dataCtrl">
<script type="text/javascript">
    var data = <?php echo json_encode(apicall("dummyarg")); ?>;
    //PASS TO ANGULAR
    //$scope.data = $window.data; doesnt work
</script>
</div>

And in js I have:

(function() {
    var app = angular.module('table', ['ngTouch', 'ui.grid']);
    app.controller("DataController", ["$scope", '$window', function($scope, $window){

        $scope.data = {};

    }]);
})();
Community
  • 1
  • 1
tjarles
  • 113
  • 1
  • 13
  • 1
    You would need to be more specific about what the problem is. To load data, you would use $http. If you have a RESTful API, and plan on full CRUD functionality, you may benefit from $resource. If your data is on $scope.gridOptions, you make your call, and then set $scope.gridOptions.data to the returned dataset. – Brian Jun 30 '16 at 22:47
  • I have to use php to load the data because of authorization. In my php I hava managed to load the results from the api call through php to a javascript object. This object must then be passed on to the controller in angular. – tjarles Jul 01 '16 at 08:34

0 Answers0