I want to create a routing config from JSON data pulled from a database but 
every tutorial/example that I have found shows a config that has been hand 
typed. What I have tried is to create a nav items service which works fine 
if used within a component as an injectable. But I need it to work in the 
routing module to register the routes, but it doesn't. Is there a 
recommended way to do this. Here is my code;

app-routing.module.ts
import { NgModule } from '@angular/core';import { RouterModule, Routes } from 
'@angular/router';import { NavService } from './nav.service';
var navService: NavService;const routes: Routes = navService.getRoutes();
@NgModule({
    imports: [RouterModule.forRoot(routes)],
    exports: [RouterModule]})
export class AppRouting{}


nav.service.ts
import { Injectable } from '@angular/core';import { Http } from 
'@angular/http';import 'rxjs/add/operator/map';import 
'rxjs/add/operator/toPromise';
@Injectable()
export class SiteNavService{
    private _navUrl = 'pathtofile/?action=ajax_site_nav';constructor(private 
_http: Http){}
    getNav(){
        return this._http.get(this._navUrl)
        .map( res => res.json())
        .toPromise();
    }
}




-- 
You received this message because you are subscribed to the Google Groups 
"Angular" 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