Hi folk !!! I want to use a factory as a provider within a module configuration and then use it within controller of state. When I execute my code and i click on an option that enters the state "main" appears this error:
<https://lh3.googleusercontent.com/-oxTIp0momIg/VVWhFD48ihI/AAAAAAAAAPE/ayldarwRKFQ/s1600/Captura.PNG> On the other hand, when I put the call to appMenuItemsSrv within resolve block works fine but every time that I click on an option it executes the service and gets the menu items from database again. I just want execute the service one time when the app has been loaded. In this way it works fine. resolve: { loadPartial: ['$ocLazyLoad', function($ocLazyLoad) { // Load files for main module return $ocLazyLoad.load('app/modelador/modelador.module.js'); }], dbData: function(appMenuItemsSrv, $http, $q, CONFIG_EBPM) { return appMenuItemsSrv .getData($http, $q, CONFIG_EBPM.APP_URL_PLSQL) .then(function(data) { return data; }) .catch(function(err) { return err; }); } } I'm using ui-router and ocLazyLoad because I've a huge app. Check out my code: *app.module.js* (function() { 'use strict'; angular .module('ebpm', ['ui.router', 'oc.lazyLoad', 'ebpm.navbar']) .constant('CONFIG_EBPM', { APP_NAME: 'Expert BPM', APP_ID: 'WKFLW', APP_AUTHOR: 'Antonio Pérez', APP_COMPANY: 'Datadec, S.A.', APP_VERSION: 1.0, APP_URL_PLSQL: 'http://sp.idatadec.es:7778/cliente/' }) .config(configRoutes); configRoutes.$inject = ['$urlRouterProvider', '$stateProvider', '$ocLazyLoadProvider']; function configRoutes($urlRouterProvider, $stateProvider, $ocLazyLoadProvider, $http, $q, appMenuItemsSrv) { // Configuration for Lazy load. $ocLazyLoadProvider.config({ debug: true, events: true }); var dbData = function(appMenuItemsSrv, $http, $q, CONFIG_EBPM) { return appMenuItemsSrv .getData($http, $q, CONFIG_EBPM.APP_URL_PLSQL) .then(function(data) { return data; }) .catch(function(err) { return err; }); } //$urlRouterProvider.otherwise('/'); // All routes of Expert BPM $stateProvider .state('main', { url: '/home/:urlMenu', templateUrl: 'app/components/main.html', controller: function($stateParams, dbData) { console.log(dbData); this.getUrlMenu = function() { return $stateParams.urlMenu; } }, controllerAs: 'main', resolve: { loadPartial: ['$ocLazyLoad', function($ocLazyLoad) { // Load files for main module return $ocLazyLoad.load('app/modelador/modelador.module.js'); }] } }) .state('main.detail', { url: '/detail/:urlTree', templateUrl: 'app/modelador/contenido.html', controller: function($stateParams) { console.log('entra partial2'); this.getUrlTree = function() { return $stateParams.urlTree; //return $sce.trustAsResourceUrl($stateParams.urlPlsql); } }, controllerAs: 'detail' }); } })(); *app.service.js* (function() { 'use strict'; angular .module('ebpm') .provider('appMenuItemsSrv', appMenuItemsSrv); function appMenuItemsSrv() { this.$get = function() { return { getData: getData } } function getData ($http, $q, dbhost) { var deferred = $q.defer(); $http.get(dbhost + 'PK_WF_MODELADOR_PROCESOS_WS.P_GET_ARBOL') .success(function(data) { deferred.resolve(data); }) .error(function(err) { deferred.reject(err); }) return deferred.promise; } } })(); -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
