connect AngularJS to mysql using my PHP service?

后端 未结 2 794
天涯浪人
天涯浪人 2020-12-15 12:46

I am using AngularJS 1.0, PHP, and mysql with localhost on my Mac.

I have a very simple mysql database: \"cats\". It has one table called \"kittens\". The table ha

2条回答
  •  甜味超标
    2020-12-15 13:33

    This should also work. It's significantly fewer lines of code, but note that any error handling has been removed:

    function FetchCtrl($scope, $resource) {
      var services = $resource('../services/index.php');
      $scope.data = services.query();
    }
    FetchCtrl.$inject = ['$scope', '$resource'];
    

    Normally I would have used the built in .get() method on the $resouce but your response is in the form of an Array, which .query() supports by default.

    You can find the documentation on $resource here

提交回复
热议问题