簡體   English   中英

在ui路由器控制器中訪問服務的問題

[英]Issue on access a service in a ui-router controller

我在嘗試訪問控制器上的服務時遇到問題。 當調用Ordenes服務時,會發生此問題。 如何使用ui-router從控制器的作用域中的值調用具有兩個參數的服務?

我有相同的代碼工作,但不使用ui-router。 似乎代碼未正確加載Controller內部的服務。

App.js

'use strict';

app = angular.module('logica-erp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ui.router',
  'authorization',
  'ui.router.stateHelper', 
  'logica-erp.kds',
  'logica-erp.pos'
])

app.run(function($rootScope) {
  $rootScope.$on("$stateChangeError", console.log.bind(console));
});

app.config(function ($stateProvider, $urlRouterProvider) {
    //delete $httpProvider.defaults.headers.common['X-Requested-With'];
    $urlRouterProvider.otherwise('/');
    $stateProvider
      .state('index', {
        url: '/',
        templateUrl: 'views/main.html',
        controller:'MainCtrl'
      })
      .state('comanda', {
        url: '/comanda',
        templateUrl: 'views/comanda.html',
        controller:'ComandaCtrl'
      })
      .state('counter', {
        url: '/counter',
        templateUrl: 'views/counter.html',
        controller:'CounterCtrl'

      })
  })

comanda.js

(function() {
  'use strict';
  var app;

  app = angular.module('logica-erp.kds', ['timer', 'logica-erp.service.pos']);

  this.ComandaCtrl = [
    '$scope', '$interval', 'Ordenes', function($scope, $interval, Ordenes) {
      var error, stop, success, tick;
      $scope.tiempos = [
        {
          name: '15 seg',
          value: 15000
        }, {
          name: '30 seg',
          value: 30000
        }, {
          name: '60 seg',
          value: 60000
        }, {
          name: '120 seg',
          value: 120000
        }
      ];
      $scope.selected_tiempo = $scope.tiempos[1];
      $scope.tipos = [
        {
          name: 'Alimentos',
          value: 'a'
        }, {
          name: 'Bebidas',
          value: 'b'
        }, {
          name: 'Todos',
          value: ''
        }
      ];
      $scope.selected_tipo = $scope.tipos[2];
      success = function(result) {
        if (angular.toJson(result) !== angular.toJson($scope.ordenes)) {
          $scope.isLoading = true;
          $scope.ordenes = result;
          console.log(JSON.stringify($scope.ordenes));
        }
        return $scope.isLoading = false;
      };
      error = function(error) {
        console.log('error ' + error);
        return $('#modal').foundation('open');
      };
      tick = function() {
        $scope.platos = Ordenes.query({
          tipo: $scope.selected_tipo.value,
          sucursal: 2
        });
        return $scope.platos.$promise.then(success, error);
      };
      tick();
      stop = $interval(tick, $scope.selected_tiempo.value);
      $scope.change_refresh = function() {
        $interval.cancel(stop);
        return stop = $interval(tick, $scope.selected_tiempo.value);
      };
      return $scope.update_order = function(mesa, aaybb_id) {
        return angular.forEach($scope.ordenes.mesas, function(orden) {
          if (orden.mesa === mesa) {
            return angular.forEach(orden.aaybb, function(aaybb) {
              if (aaybb._id === aaybb_id) {
                if (aaybb.estatus === 'ASIGNADO') {
                  aaybb.estatus = 'EN PROCESO';
                } else if (aaybb.estatus === 'EN PROCESO') {
                  aaybb.estatus = 'PREPARADO';
                  $('#timer_' + aaybb._id)[0].stop();
                }
                return Ordenes.update(aaybb);
              }
            });
          }
        });
      };
    }
  ];

  app.controller('ComandaCtrl', ComandaCtrl);

}).call(this);

控制台日志

Error: value is undefined
extractParams/<@http://127.0.0.1:9000/bower_components/angular-resource/angular-resource.js:344:11
forEach@http://127.0.0.1:9000/bower_components/angular/angular.js:336:11
extractParams@http://127.0.0.1:9000/bower_components/angular-resource/angular-resource.js:343:9
ResourceFactory/</Resource[name]@http://127.0.0.1:9000/bower_components/angular-resource/angular-resource.js:398:39
this.ComandaCtrl</tick@http://127.0.0.1:9000/scripts/controllers/comanda.js:72:25
this.ComandaCtrl<@http://127.0.0.1:9000/scripts/controllers/comanda.js:78:7

我解決了這個問題,它是angular-source庫中的一個舊錯誤。 我不知道,但是我的涼亭還是安裝了1.0.7版本:S; 這很煩人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM