0

I have an API which returns an array, which I want to use inside route Config of my $stateProvider... but am unable to do so.

Can someone help me, I have tried using localStorage and $rootScope

Below in my code snippet:

(function() {
    'use strict';

    angular.module('Admin.pages.masters', ['ui.select', 'ui.bootstrap', 'ngSanitize'])
      // .run(function($rootScope){
      //   $rootScope.arr = ['System Admin','System Manager', 'System User'];
      // })  
      .config(routeConfig);

    /** @ngInject */
    function routeConfig($stateProvider, $httpProvider) {
      //localStorageServiceProvider.setStorageType('localStorage');
      //console.log(localStorage.getObject('userData'));
      $httpProvider.interceptors.push('authInterceptor');
      $stateProvider
        .state('main.master', {
          url: '/master',
          template: '<ui-view autoscroll="true" autoscroll-body-top></ui-view>',
          abstract: true,
          title: 'Masters',
          sidebarMeta: {
            icon: 'icoMasters',
            order: 2,
          },
          authenticate: true,
          params: { // <-- focusing this one
            authRoles: ['System Admin', 'System Super Admin'] // <-- roles allowed for this module
          }
        })
        .state('main.master.license', {
          url: '/license',
          template: '<ui-view autoscroll="true" autoscroll-body-top></ui-view>',
          title: 'Customer License',
          sidebarMeta: {
            order: 0,
          },
          authenticate: true,
          params: { // <-- focusing this one
            authRoles: ['System Admin', 'System Super Admin'] // <-- roles allowed for this module
          }
        })
Dave1
  • 48
  • 1
  • 10
  • can you resolve it instead of providing parameters? e.g. `resolve: { authRoles: function resolveAuth( AuthService ) { return AuthService.getAuthRoles(); } }`. Then just do whatever you want in a service: store static array, or load a dynamic one. Whenever you need those values, just inject your resolve: `.controller("ctrl", function(authRoles){...})` – Aleksey Solovey Jul 17 '18 at 13:47
  • As a side note... the iife is not being called. It lacks of the `()` at the end: `}())` or `})()` – lealceldeiro Jul 17 '18 at 13:56
  • params accept an object. that object can be literal and its properties should be able to be any JS object, including an array. Are you sure problem is with it being array? – DanteTheSmith Jul 17 '18 at 13:57
  • @lealceldeiro i didn't add my full code only part of it does ends with })(); – Dave1 Jul 18 '18 at 00:49
  • @DanteTheSmith am open for object interation also, it still has problem with both array anf object, i want to use my api data in params->authRoles. – Dave1 Jul 18 '18 at 00:51
  • I tried it with resolve also but my state params are still not getting loaded, they show as blank. – Dave1 Jul 20 '18 at 10:32

0 Answers0