问题就在访问的UI路由器控制服务 [英] Issue on access a service in a ui-router controller
问题描述
我有尝试在控制器上访问服务的问题。当Ordenes服务被称为问题发生。我怎么能叫一个服务使用的用户界面,使用路由器值的两个参数,从控制器范围有多大?
我有同样的code工作,但在不使用UI的路由器。这似乎是code未正确加载控制器内部的服务。
App.js
使用严格的;应用= angular.module('逻-ERP,[
ngCookies',
ngResource',
ngSanitize',
ui.router',
'授权',
ui.router.stateHelper',
逻-erp.kds',
逻-erp.pos
])app.run(函数($ rootScope){
$ rootScope在$($ stateChangeError,console.log.bind(控制台))。
});的app.config(函数($ stateProvider,$ urlRouterProvider){
//删除$ httpProvider.defaults.headers.common ['X-要求-随着'];
$ urlRouterProvider.otherwise('/');
$ stateProvider
.STATE('指数',{
网址:'/',
templateUrl:意见/ main.html中,
控制器:'MainCtrl
})
.STATE('comanda',{
网址:'/ comanda',
templateUrl:意见/ comanda.html',
控制器:'ComandaCtrl
})
.STATE('反',{
网址:'/计数器,
templateUrl:意见/ counter.html',
控制器:'CounterCtrl })
})
comanda.js
(函数(){
使用严格的;
VAR应用; 应用= angular.module('逻-erp.kds',['定时','逻-erp.service.pos']); this.ComandaCtrl = [
'$范围,$间隔,Ordenes',函数($范围,$区间,Ordenes){
VAR错误,停止成功,剔;
$ scope.tiempos = [
{
名称:'15赛格,
值:15000
},{
名称:'30赛格,
值:30000
},{
名称:'60赛格,
值:60000
},{
名称:'120赛格,
值:120000
}
];
$ scope.selected_tiempo = $ scope.tiempos [1];
$ scope.tipos = [
{
名称:'ALIMENTOS',
值:'A'
},{
名称:'BEBIDAS',
值:'B'
},{
名称:'托多斯',
值:''
}
];
$ scope.selected_tipo = $ scope.tipos [2];
成功=功能(结果){
如果(angular.toJson(结果)!== angular.toJson($ scope.ordenes)){
$ scope.isLoading = TRUE;
$ scope.ordenes =结果;
的console.log(JSON.stringify($ scope.ordenes));
}
返回$ scope.isLoading = FALSE;
};
错误=功能(错误){
的console.log('错误'+误差);
返回$('#模')基金会(开放)。
};
勾选=功能(){
$ scope.platos = Ordenes.query({
类型:$ scope.selected_tipo.value,
sucursal:2
});
返回$ scope.platos $ promise.then(成功,错误)。
};
蜱();
停止= $间隔(打勾,$ scope.selected_tiempo.value);
$ scope.change_refresh =功能(){
$ interval.cancel(停止);
返回停止= $间隔(打勾,$ scope.selected_tiempo.value);
};
返回$ scope.update_order =功能(台面,aaybb_id){
返回angular.forEach($ scope.ordenes.mesas,功能(奥登){
如果(orden.mesa ===台面){
返回angular.forEach(orden.aaybb,功能(aaybb){
如果(aaybb._id === aaybb_id){
如果(aaybb.estatus ==='ASIGNADO'){
aaybb.estatus =EN PROCESO';
}否则如果(aaybb.estatus ==='EN PROCESO'){
aaybb.estatus ='prePARADO';
$('#timer_'+ aaybb._id)[0] .stop();
}
返回Ordenes.update(aaybb);
}
});
}
});
};
}
]; app.controller('ComandaCtrl',ComandaCtrl);})调用(本);
控制台日志
错误:值为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.js:336:11
extractParams @ HTTP://127.0.0.1:9000 / bower_components /角资源/角resource.js:343:9
ResourceFactory/</Resource[name]@http://127.0.0.1:9000/bower_components/angular-resource/angular-resource.js:398:39
this.ComandaCtrl&LT; /剔@ HTTP://127.0.0.1:9000 /脚本/控制器/ comanda.js:72:25
this.ComandaCtrl&LT; @http://127.0.0.1:9000 /脚本/控制器/ comanda.js:78:7
我固定的问题,这是一个老臭虫角资源库。我不知道,但我的凉亭被安装1.0.7版本:反正S;这是很烦人的。
I am having issues trying to access a service on a controller. The issue happen when the Ordenes services is called. How I can call a service with two parameter using values from the scope from a controller using ui-router?
I have the same code working but without the use of ui-router. It seems like the code is not loading properly the service inside the 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);
Console log
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
I fixed the issue, it was a old bug in the angular-resource lib. I didn't know but my bower was installing version 1.0.7 :S anyway; this was very annoying.
这篇关于问题就在访问的UI路由器控制服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!