php - How to connect (route) Angular with Slim Framework API? -


i cannot populate json data in controller service.

i bit stuck how connect them. service works fine when called generating json. controller works when used repository. omitted code in order save space.

the problem lies in controller, don't know what. appreciate enlightenment.

angular controller (root/app/user.controller.js)

(function() {      angular     .module('app')     .controller('usercontroller', usercontroller);      function usercontroller($http) {         var = this;          $http({             method: 'get',             url: '/api/users'         }).success(function(data) {             that.users = data;          });     }    })();    

php service (root/api/index.php)

<?php  require 'vendor/autoload.php';  $app = new \slim\app;   $app->get('/users', 'getusers');  $app->run();  function getusers() {     $sql = "select * users order id";     try {         $db = getconnection();         $stmt = $db->query($sql);           $wines = $stmt->fetchall(pdo::fetch_obj);         $db = null;         echo json_encode($wines);     } catch(pdoexception $e) {         echo '{"error":{"text":'. $e->getmessage() .'}}';      } }     ?> 

json result php sevice visiting http://localhost/root/api/users

[{"id":"1","username":"lucentx","first_name":"aron","last_name":"barbosa","address":"manila, philippines"},{"id":"2","username":"ozzy","first_name":"ozzy","last_name":"osbourne","address":"england"},{"id":"3","username":"tony","first_name":"tony","last_name":"iommi","address":"england"}] 

html view (index.html)

<div class="col-md-4" ng-controller="usercontroller userctrl">     <ul class="list-group">         <li class="list-group-item" ng-repeat="user in userctrl.users">             <p>{{user.id}} - {{user.username}}</p>         </li>     </ul> </div> 

try removing leading / in url tell browser start @ root of site ... not in directory want to


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -