0

i can't make it works. Could somebody help me? I would like to show user detail information after click on link, but i don't know how to send information to php file with a link.

i have link to detailed user information like:

<tr ng-repeat="user in users | filter:searchText | orderBy:'finish_date'">
          <td><a href="#/user/{{user.user_id}}">{{user.name + ' ' + user.lastname}}</a></td>
          <td> {{user.begin_date}}</td>
          <td> {{user.finish_date}}</td>
</tr>

and controller:

gymiControllers.controller('UserDetailCtrl', ['$scope', '$http',  function ($scope, $http) {
      console.log($scope.user.user_id);
      $http.get('php/UserDetailsGetData.php?user_id=user.user_id"').success(function(data) {
        $scope.user = data;
      });
    }]);

and php file, which should get variable from angular ;-):

$user_id = $_GET['user_id'];
2
  • 1
    you're passing the string "user.user_id" as the user_id parameter Commented Apr 12, 2016 at 16:16
  • console.log in UserDetailCtrl Controller say it: TypeError: Cannot read property 'user_id' of undefined. How to retrieve it from this angular thing :) Commented Apr 12, 2016 at 18:18

1 Answer 1

2

Correct it to:

gymiControllers.controller('UserDetailCtrl', ['$scope', '$http',  function ($scope, $http) {
      console.log($scope.user.user_id);
      $http.get('php/UserDetailsGetData.php?user_id='+$scope.user.user_id).success(function(data) {
        $scope.user = data;
      });
    }]);
Sign up to request clarification or add additional context in comments.

4 Comments

seems does not work: TypeError: Cannot read property 'user_id' of undefined
is 'UserDetailCtrl' the controller of your ng-repeat?
ng-repeat with link is contained in "ActiveListCtrl" controller and after click ngRoute directs to another view with controller "UserDetailCtrl"
that's why the $scope is empty. I suggest you to save the User information in a Factory or Angular Service and then inject it in UserDetailsCtrl, alternatively you could use a localstorage or $rootscope but it would be a bad choice.

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.