This is used as a custom resolver on the route you want to load the JS API modules on as per https://blog.thoughtram.io/angular/2016/10/10/resolving-route-data-in-angular-2.html.
you can then access the modules by injecting ActivatedRoute
into your component and looking at this.route.snapshot.data['esri']['Map']
.
import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { EsriModuleResolveService } from "./esri-module-resolve.service";
import { MapViewComponent } from "./map-view.component";
const routes: Routes = [
{
path: "map",
component: MapViewComponent,
resolve: { esri: EsriModuleResolveService },
data: {
esriModules: {
Map: "esri/Map",
MapView: "esri/views/MapView",
FeatureLayer: "esri/layers/FeatureLayer",
Legend: "esri/widgets/Legend"
}
}
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MyRoutingModule {}