Ionic + Angularjs error list item

Asked

Viewed 109 times

0

I made a list in Ionic that returns some values, but when I click on the list to show these values completely, I am not able to recover...

my controller:

    app.factory('services', ['$http', function($http) {
    var obj={};
    obj.getPessoas = function() { return $http.get('http://xxxx.com.br/conecta.php'); }
    return obj;
}]);

app.controller("pessoasCtrl", function($scope, services,$ionicScrollDelegate) {
    services.getPessoas().then( function(data) {
        $scope.pessoas = data.data;
    } )

    $scope.scrollTop = function() {
        $ionicScrollDelegate.scrollTop(true);   
    }; 
})

my app.js

.state('tab.chats', {
      url: '/chats',
      views: {
        'tab-chats': {
          templateUrl: 'templates/tab-chats.html',
          controller: 'pessoasCtrl'
        }
      }
    })
    .state('tab.chat-detail', {
      url: '/chats/:chatId',
      views: {
        'tab-chats': {
          templateUrl: 'templates/chat-detail.html',
          controller: 'pessoasCtrl'
        }
      }
    })

The call on the chats page:

<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="pessoa in pessoas" type="item-text-wrap" href="#/tab/chats/{{pessoa.DOU_CODIGO}}">
        <img ng-src="{{pessoa.face}}">
        <h2>{{pessoa.DOU_NOME}}</h2>
        <p>{{chat.DOU_ESPECIALIDADE}}</p>
        <i class="icon ion-chevron-right icon-accessory"></i>
      </ion-item>

and when I click on each line, I can’t recover on the chat-Detail that looks like this:

<ion-view view-title="{{pessoa.DOU_CODIGO}}">
  <ion-content class="padding">
    <img ng-src="{{pessoa.face}}" style="width: 64px; height: 64px">
    <p>
      {{pessoa.DOU_CODIGO}}
    </p>
  </ion-content>
</ion-view>

1 answer

0

I didn’t see in your controller where you try to redeem the value of the ID you passed, we usually use the $stateParams.NomeDoparametro.
I would do this: Take out href and call a function in ng-click

ng-click="selecionaPessoa(pessoa)"

This way you pass all the selected object, without having to select again. Ai just add the person to Scope within the function:

$scope.selecionaPessoa = function(pessoa){
    $scope.selecionado = pessoa;
};

In your HTML just call {{selecionado.DOU_CODIGO}}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.