javascript - AngularJS won't update view but $scope does -


i'm using ionic framework build app. have item list (productos.html). each of them <a> tag href detail (producto.html). can sell product there registrarventa method. callback calls listarproductos method, retrieve updated products list (the sold product not there). method transitions app.productos state, have show $scope.productos list. $scope.productos updated, ng-repeat productos not! cant use $scope.$apply() function. ideas?

ps: excuse me english, native languge

app.js

angular.module('starter', ['ionic', 'ngcordova', 'starter.controllers',      'starter.services', 'starter.filters', 'starter.factories'])  .run(function($ionicplatform) {     $ionicplatform.ready(function() {         // hide accessory bar default (remove show accessory bar above keyboard         // form inputs)         if (window.cordova && window.cordova.plugins.keyboard) {             cordova.plugins.keyboard.hidekeyboardaccessorybar(true);             cordova.plugins.keyboard.disablescroll(true);         }         if (window.statusbar) {             // org.apache.cordova.statusbar required             statusbar.styledefault();         }     }); })  .config(function($stateprovider, $urlrouterprovider) {     $stateprovider     .state('app', {         url: '/app',         abstract: true,         templateurl: 'views/menu.html',         controller: 'appctrl'     })     .state('app.productos', {         url: '/productos',         views: {             'menucontent': {                 templateurl: 'views/productos.html',                 controller: 'productoscontroller'             }         }     })     .state('app.producto', {         url: '/productos/:idproducto',         views: {             'menucontent': {                 templateurl: 'views/producto.html',                 controller: 'productoscontroller'             }         }     })      // if none of above states matched, use fallback     $urlrouterprovider.otherwise('/app/productos'); }); 

controllers.js

angular.module('starter.controllers', [])     .controller('productoscontroller', function($scope, $q, $http, $state, $stateparams) {         $scope.idproductoseleccionado = $stateparams.idproducto;         $scope.busqueda;         $scope.venta = {             cliente: 1,             variante: $scope.idproductoseleccionado,             entrega: null         };         $scope.productos = null;          $scope.listarproductos = function(){             $scope.productos = null;             var defer = $q.defer();             $http.get(url + 'productos')             .then(function(response){                 $scope.productos = response.data.productos;                 console.log('productos callback', $scope.productos); //it works every time wont update view                 defer.resolve(true);             }, function(error){                 $scope.productos = null;                 console.log(error);                 defer.reject(error);             });             return defer.promise;         };         $scope.listarproductos();          $scope.registrarventa = function(){             $scope.productos = null;             var defer = $q.defer();             $http.post(url + 'registrar-venta', $scope.venta)             .then(function(response){                 console.log('productos before', $scope.productos);  //non-updated list => ok                 $scope.listarproductos();                 console.log('productos after', $scope.productos);  //null => ok                  $scope.venta = null;                 $state.go('app.productos');                  defer.resolve(response.data.message);             }, function(error){                 if(window.plugins && window.plugins.toast) {                     window.plugins.toast.showlongcenter(error);                 } else {                     console.error(error);                 }                 defer.reject(error);             });             return defer.promise;         };     }) 

productos.html

<ion-view view-title="productos"> <ion-content> <div class="content padding">     <h1 class="title">productos</h1>     <div class="list list-inset">         <label class="item item-input">             <i class="icon ion-search placeholder-icon"></i>             <input ng-disabled="!productos" type="text" placeholder="buscar productos" ng-model="busqueda" >         </label>     </div>     <div ng-show="!productos" class="loading"><ion-spinner icon="dots"></ion-spinner> <span>cargando productos...<span></div>      <ul class="list">         <!--  | searchfor:busqueda -->         <a class="item item-thumbnail-left" ng-repeat="producto in productos | searchforproducto:busqueda " href="#/app/productos/{{producto.idvariante}}">             <img src="{{producto.foto}}">             <h2>{{producto.nombre}}</h2>             <p><strong>talles:</strong> {{producto.talles}}</p>             <p><strong>colores:</strong> {{producto.colores}}</p>             <span class="badge badge-assertive badge-normal">$ {{producto.precioventa}}</span>         </a>     </ul> </div> </ion-content> </ion-view> 


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -