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 = {};

    }]);
})();
2
  • 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. Commented Jun 30, 2016 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. Commented Jul 1, 2016 at 8:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.