0

I'm trying to download a JSON with their data, but for some reason will not run, and the entire application breaks. And I'd like when Pull to refresh all the information JSON is refreshed.

This is Services.js:

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

.factory('NotasService', function($resource,$http) {
return {

  all: function() {
    var items_nota;
      $http.get('http://betamediagroup.net/apps/canalDiez/estructura.json ')
          .success(function(data) {
           items_nota = data.datos;
          });
       return items_nota;
       },
     get: function(notaId) {
    // Simple index lookup
       return items_nota[notaId];
     }
      }
    });

This is Controller.js

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

.controller('ActulidadCtrl', function($scope, NotasService, $timeout) {

    $scope.items_nota = NotasService.all();
    $scope.isActualidad = function(items_nota) {
        return items_nota.category === "ahora";
    };

    //Pull tu refresh
        $scope.doRefresh = function() {

        console.log('Actualizando!');
        $timeout( function() {

        $scope.items_nota.push({
          id: 3,
          titulo: 'Balcarce: Marangoni en los 70 años del Banco Provincia.',
          fecha: '03 nov 09.30',
          foto: 'actualidad_marangoni'
        });
        $scope.items_nota.push({
          id: 4,
          titulo: 'Temporal: el Gobierno Provincial asiste a los daminficados.',
          fecha: '03 nov 09.00',
          foto: 'actualidad_temporal'
        });
        //Stop the ion-refresher from spinning
        $scope.$broadcast('scroll.refreshComplete');

        });

    };
})

And this is template view:

<ion-view>
    <ion-nav-buttons side="left">
        <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>>
    </ion-nav-buttons>

    <ion-content class="has-header">
        <ion-refresher on-refresh="doRefresh()" pulling-text="Tire para actualizar..." refreshing-text="Actualizando!" refreshing-icon="ion-loading-c">
        </ion-refresher>
        <ion-list>    
            <ion-item ng-repeat="item in items_nota" href="#/app/nota/{{item.id}}">
                <img src="img/{{item.foto}}">
                <h2>{{item.titulo}}</h2>
                <p >{{item.fecha}}</p>
            </ion-item>
        </ion-list>
    </ion-content>
</ion-view>

UPDATE: solved the problem was in the JSON structure

1
  • UPDATE: solved the problem was in the JSON structure Commented Dec 27, 2018 at 10:31

2 Answers 2

1

Try this

.factory('NotasService', function($resource,$http) {
    var items_nota;

    $http.get('http://betamediagroup.net/apps/canalDiez/estructura.json ')
        .success(function(respuesta) {
      items_nota = respuesta.data;
    });
  };

  return {
    all: function() {
      return items_nota;
    },
    get: function(notaId) {
      // Simple index lookup
      return items_nota[notaId];
    }
  }
});

The rason of application breaks is you didnt pass $http in your service

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

Comments

1

1- you have a small typo

2- you must pass $http to your factory

3- your items_nota should be equal to the data dotas array not to the request data

.factory('NotasService', function($resource,$http) {
     return {

all: function() {
  var items_nota;
    $http.get('http://betamediagroup.net/apps/canalDiez/estructura.json ')
        .success(function(data) {
         items_nota = data.datos;
        });
     return items_nota;
     },
   get: function(notaId) {
  // Simple index lookup
     return items_nota[notaId];
   }
    }
  });

1 Comment

While the application is not now, if the following problem is generated breaks, it shows me a white screen betamediagroup.net/apps/canalDiez/unnamed.png betamediagroup.net/apps/canalDiez/unnamed1.png

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.