I am trying to make an $http call inside my publicApp.config in order to 
retrieve an array of available routes to match with the 
$urlMatcherFactoryProvider.


Right now, I am hard-coding them to be pageUrls = 
['about','contact','another-page'];


But I have an url in my express API which returns an array of available 
URLS. The api URL is "/page-urls"


Would it be possible to make an $http.get('/page-urls') request inside the 
config? I know $http is available inside run(), but I need the list of 
available URLs BEFORE routing via the $stateProvider.


(function() {
    'use strict'

    var pageUrls = [];

    var publicApp = angular.module('publicApp', ['ui.router'])

    publicApp.config(['$stateProvider', '$urlRouterProvider', 
'$urlMatcherFactoryProvider', function($stateProvider, $urlRouterProvider, 
$urlMatcherFactoryProvider) {

        pageUrls = ['about','contact','another-page'];  

        var urls = pageUrls.join('|');
        var urlMatcher = $urlMatcherFactoryProvider.compile("/{source:(?:" + 
urls + ")}");


        $stateProvider      
            .state('/', {
                url: '/',
                templateUrl: "views/home/home.view.html",
                controller: "homeCtrl"
            })
            .state('urls', {
                    url: urlMatcher,
                    templateUrl: "views/pages/page.view.html",
                    controller: "pageCtrl"
                });

            $urlRouterProvider.otherwise('/');


    }]);


})();

-- 
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 https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to