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-map
and useEsriLoaderService
to show a map
- copy code from
esri-map.component.ts
andesri-map.component.css
esri-map.component.html
below
- Add the following to the bottom of the
import
statements 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
providers
to 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.types
in 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
Hi, I have a problem with this. I followed the steps indicated but when I start the page I get the following error:
Uncaught Error: Can't resolve all parameters for EsriMapComponent: (?). ------------------------------------------------compiler.es5.js:16000
at syntaxError (http://localhost:4200/vendor.bundle.js:49418:34)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getDependenciesMetadata (http://localhost:4200/vendor.bundle.js:63497:35)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver._getTypeMetadata (http://localhost:4200/vendor.bundle.js:63365:26)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:4200/vendor.bundle.js:62960:24)
at CompileMetadataResolver.webpackJsonp.../../../compiler/@angular/compiler.es5.js.CompileMetadataResolver.loadDirectiveMetadata (http://localhost:4200/vendor.bundle.js:62824:25)
at http://localhost:4200/vendor.bundle.js:74534:72
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:74533:72
at Array.forEach (native)
at JitCompiler.webpackJsonp.../../../compiler/@angular/compiler.es5.js.JitCompiler._loadModules (http://localhost:4200/vendor.bundle.js:74530:75)
Any idea why this is happening ???
Thank you