title: AngularJs view user details
body: <p>I'm building a website and I have some users, or clients. For this, I have a general table with just some basic information like <code>name</code>, <code>type</code> and <code>e-mail</code>, and I want to show all the client/user information in another page, because each client/user will have a lot more information, like phone, address, etc..</p>
  
  <p><strong>Old Method</strong><br />
  Since I'm new to angularjs, I couldn't do it yet. I have an old website, working with HTML and PHP. The way I do it is to send the user id through the url, then, in the new page (<code>det_user.php</code>), I get this URL parameter to call all the user information and then load it into a table.</p>
  
  <p>Is this the best way to do it with AngularJS?
  If there is another method to it without sending the id through the URL, but to keep the user able to refresh/share the page link, please tell me.</p>
  
  <p><em>What I tried to do</em></p>
  
  <p>I was looking for an answer everywhere I could, but couldn't found any complete answer, just some parts. So here is what I tried so far:</p>
  
  <p><strong><em>scripts.js</em></strong></p>
  
  <pre><code>var myApp=angular.module("myApp",["ngRoute"]);
  
  myApp.config(function ($routeProvider, $locationProvider) {
      $routeProvider
          .when('/Home',
          {
              controller: 'HomeCtrl',
              templateUrl: 'content/home.html'
          })
          .when('/cliente',
          {
              controller: 'ClienteCtrl',
              templateUrl: 'content/cliente.html'
          })
          .when('/detcli/:id',
          {
              controller: 'DetCli',
              templateUrl: 'content/detclinte.html'
          })
          .otherwise({
              redirectTo: '/Home'
          });
  });
  
  myApp.controller('ClienteCtrl', function ($scope, $http, $routeParams) {
      $scope.get_cliente = function() {
          $scope.loading = true;
          $http.get("scripts/php/db.php?action=get_cliente")
          .success( function(data) {
              $scope.pagedClientes = data;
              $scope.loading = false;
          })
          .error(function(data) {
          });
      };
  });
  
  myApp.controller('DetCli', function ($scope, $http, $routeParams) {
      var clienteId = $routeParams.clienteId;
      //more functions here?
  });
  </code></pre>
  
  <p><strong><em>cliente.html</em></strong></p>
  
  <pre><code>&lt;div class="block" ng-controller="ClienteCtrl"&gt;
  &lt;tbody ng-init="get_cliente()"&gt;
      &lt;tr ng-repeat="cliente in pagedClientes | filter:searchField | filter:clifilter | orderBy:sortType:sortReverse"&gt;
          &lt;td&gt;{{cliente.nome}}&lt;/td&gt;
          &lt;td&gt;{{cliente.tipo}}&lt;/td&gt;
          &lt;td&gt;{{cliente.email}}&lt;/td&gt;
          &lt;td &gt;
              &lt;a href="#/detcliente/:clienteid"&gt;View&lt;/a&gt;
              &lt;a ng-click="cli_edita(cliente.id)"&gt;Edit&lt;/a&gt;
              &lt;a ng-click="cli_deleta(cliente.id)"&gt;Del&lt;/a&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong><em>detcliente.html</em></strong><br />
  <em>I'm not really sure how to work the code on this page</em></p>
  
  <pre><code>&lt;div class="block" ng-controller="DetCli"&gt;
      &lt;tbody ng-init="get_detcliente()"&gt;
          &lt;tr&gt;
              &lt;td&gt;Name&lt;/td&gt;
              &lt;td&gt;{{cliente.nome}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Email&lt;/td&gt;
              &lt;td&gt;{{cliente.email}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Phone&lt;/td&gt;
              &lt;td&gt;{{cliente.phone}}&lt;/td&gt;
          &lt;/tr&gt;
          [...more data...]
      &lt;/tbody&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Thank you for now.</p>
  
  <h1>Edit:</h1>
  
  <p>Thanks to @pankajparkar i'm almost there, i could pass the id from the cliente.html to the detcliente.html the problem now seems to be to integrate the data i'm getting from the server with the code to filter it by the id. After some search i could get this code, but still not working.. It seems to be the json data, i need to send it to filter by the id. Any idea? This is the code.</p>
  
  <pre><code>myApp.controller('DetcliCtrl', function ($scope, $http, $routeParams, $filter) {
      var clienteId = $routeParams.id;
  
      $scope.mainmsg = "Detalhes do cliente " + $routeParams.id;
      $scope.search = function() {
          var url = 'scripts/php/db.php?action=get_cliente';
          $http.get(url).success( function(data) {
              $scope.pagedClientes = data;
          }).error(function() {
              alert('Unable to get back informations :( ');
          });
      }
  
      var resultado = $filter('filter')(data.results, {id:clienteId})[0];
      $scope.nome = resultado.nome;
  
  });
  </code></pre>