NOTE: These instructions apply to trying to use the ArcGIS API for JavaScript in an Angular 2 application created w/ angular-cli. If you're working with more recent versions of Angular, you should use https://github.com/Esri/esri-loader instead.
-
Create a new Angular app by using angular-cli to generate a new project
-
Install angular2-esri-loader
npm install angular2-esri-loader esri-loader --save- Generate a new component with
ng g component esri-mapand useEsriLoaderServiceto show a map
- copy code from
esri-map.component.tsandesri-map.component.cssesri-map.component.htmlbelow
- Add the following to the bottom of the
importstatements in your application's module:
import { EsriLoaderService } from 'angular2-esri-loader';
import { EsriMapComponent } from './esri-map/esri-map.component';- Add the following to your application's
declarations:
EsriMapComponent- Add the following to your application's
providersto register angular2-esri-loader'sEsriLoaderService:
EsriLoaderService- Add the following to the end of your application component's template:
<app-esri-map></app-esri-map>That's it, run the app with ng serve
- Install the types
npm install @types/arcgis-js-api --save-dev- Add "arcgis-js-api" to
compilerOptions.typesin src/tsconfig.app.json and src/tsconfig.spec.json - Replace the contents of esri-map.component.ts with the contents of
esri-map-with-types.component.ts
Re-run the app with ng serve
Please don't leave any further comments here, I won't be notified and the gist is outdated. See https://github.com/Esri/esri-loader for the most up to date information on how to use the ArcGIS API for JavaScript in Angular applications.