0

i am trying to show a dynamic data on the ionic slide box with ng-repeat. i am using services to get the data from my sqlite DB but i get nothing. i don't know what to do after 3 days with this issue, here is my code:

template.html

<ion-view>
    <ion-nav-title>{{simple.title}}</ion-nav-title>
  <ion-content>

      <div class="row">
        <div class="col col-33 col-offset-33">
            <h1 style="font-size: 72px !important;">{{simple.content}}</h1>
        </div>
      </div>
      <div class="row">
        <div  class="col">
                <ion-slide-box show-pager="false" does-continue="true">
                    <ion-slide ng-repeat="senci in sencillo">
                       <div class="box">
                           <h1 style="font-size: 52px !important;">{{senci.sound_title}}</h1>

                       </div>
                    </ion-slide>
                </ion-slide-box>

        </div>
      </div>



  </ion-content>
</ion-view>

my service.js

angular.module('starter.services', [])

.factory('DBA', function($cordovaSQLite, $q, $ionicPlatform) {
  var self = this;

  // Handle query's and potential errors
  self.query = function (query, parameters) {
    parameters = parameters || [];
    var q = $q.defer();

    $ionicPlatform.ready(function () {
      $cordovaSQLite.execute(db, query, parameters)
        .then(function (result) {
          q.resolve(result);
        }, function (error) {
          console.warn('I found an error');
          console.warn(error);
          console.log(error.code + ' / ' + error.message);
          q.reject(error);
        });
    });
    return q.promise;
  };

  // Proces a result set
  self.getAll = function(result) {
    var output = [];

    for (var i = 0; i < result.rows.length; i++) {
      output.push(result.rows.item(i));
    }
    return output;
  };

  // Proces a single result
  self.getById = function(result) {
    var output = null;
    output = angular.copy(result.rows.item(0));
    return output;
  };

  return self;
})

.factory('Sounds', function(DBA) {
 var self = this;
 
 
 self.getSimple = function(simpleId) {
    var parameters = [simpleId];
    return DBA.query("SELECT * FROM letters WHERE Id = (?)", parameters)
      .then(function(result) {
        return DBA.getById(result);
      });
  };
  self.getSimpleArr = function(Id) {
    var parameters = [Id];
    return DBA.query("SELECT * FROM words WHERE letter_id = (?)", parameters)
      .then(function(result) {
        return DBA.getById(result);
      });
  };
 
    
  return self;  
    
});

controller.js

.controller('SoundsSimpleCtrl', function($scope, Sounds, $stateParams, $ionicSlideBoxDelegate) {
     $scope.sencillo = [];

      $scope.getSimple = function($stateParams) {
        Sounds.getSimple($stateParams.simpleId).then(function(single){
          $scope.simple = single;
          $scope.getArrSimple($scope);
        });
          
      };
      $scope.getArrSimple = function($scope){
          
          Sounds.getSimpleArr($scope.simple.Id).then(function(detalle){
           $scope.sencillo = detalle; 
           $ionicSlideBoxDelegate.update();
            });
          
      };
      $scope.getSimple($stateParams);
      });

i hope you guys can help me, regards.

16
  • Try using ng-if="simple" on the <ion-slide-box> to only show it when the SQLite data has been loaded. Commented Sep 24, 2015 at 2:35
  • Hi man, Ok, i will try this one... Commented Sep 24, 2015 at 17:27
  • i got the same result man, the slide box still does show nothing, i tried creating a $scope like this $scope.prueba = [{uno : "uno", dos:"dos"}, {uno : "tres", dos:"cuatro"}]; then i use it with ng-repeat for testing and it works, so i don't know where is the problem... Commented Sep 24, 2015 at 17:44
  • how about putting the update() call in $timeout()? Commented Sep 24, 2015 at 17:58
  • im sorry man, how can i do this? Commented Sep 24, 2015 at 18:12

1 Answer 1

0

Hi people i resolved my problem, i had a bad SQl Request, im so sorry for be annoying, i just changed to use my service function from getById() to getAll() (these functions are being taken from DBA Factory) like this:

 self.getSimpleArr = function(value) {
    var parameters = [value];
    return DBA.query("SELECT * FROM words WHERE letter_id = (?)",parameters)
        .then(function(result){
          return DBA.getAll(result);
      });
  };

the getById() function was returning only the first row of the request, absolutely MY BAD. Regards

Sign up to request clarification or add additional context in comments.

Comments

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.