Having some trouble understanding how to mix AngularJS and PHP. I am initially just trying to have an AngularJS factory make a call to a PHP file (which grabs a query), then push it back to my AngularJS factory where a Controller can use the data.
Here is what I have so far, and this gives me "undefined" when I try to console.log the result.
Factory
app.factory("PlantServiceLIVE", function($http) {
var mData = {};
$http.get('pages/getplants.php').success(function(data) {
mData.data = data;
});
return mData;
});
Controller
app.controller('TestController', function($scope, $http, PlantServiceLIVE) {
$scope.Plants = PlantServiceLIVE.mData;
console.log(JSON.parse($scope.Plants));
});
PHP (just verified that the below works tooo)
$sql = "SELECT * FROM PlantTable";
$result = $conn->query($sql);
echo json_encode($result);
Not sure what exactly I am doing wrong, first time doing this.
The only developer console errors I get are SyntaxError: Unexpected token u, which from what I read just means the data is undefined.