Using amcharts ammaps in angular 2: A step-by-step guide

I am attempting to integrate ammaps into an Angular 2 application. After reviewing the code, it appears that my component is not recognizing the library.
Here is a glimpse at my files:
map.component.html

<script src="http://www.ammap.com/lib/ammap.js" type="text/javascript">   </script>
<script src="http://www.ammap.com/lib/maps/js/worldLow.js"  type="text/javascript"></script>


<div id="mapdiv" style="width: 600px; height: 400px;"></div>

map.component.ts

import { Component } from '@angular/core';

//Utilizing a solution found in another article to avoid 
//typescript errors regarding undefined types

declare var AmCharts: any;

@Component({
selector: 'newsmap-map',
templateUrl: 'app/views/map.component.html',
directives: [],
styleUrls: ['app/css/map.component.css']
})

export class MapComponent { 

AmCharts: any;
//Using ngOnint to trigger the necessary 
//javascript code included in the html file
ngOnInit(){
     this.AmCharts = new AmCharts({
        makeChart( "mapdiv", {

          "type": "map",


          "dataProvider": {
            "map": "worldLow",
            "getAreasFromMap": true
          },


          "areasSettings": {
            "autoZoom": true,
            "selectedColor": "#CC0000"
          },


          "smallMap": {}
        } )

    }
}

}

How can I get this to function properly? Refer to the guide provided by ammaps.

Thank you!

Answer №1

To incorporate external scripts into Angular 2 templates, avoid using script tags and instead place your non-angular code within the index HTML file for successful integration.

To use custom code in Angular 2, import and load it with System.js after procuring a compatible AmCharts library from npm.

Explore further insights on this topic: Angular 2 and AmCharts

It is advisable to conduct thorough research using search engines prior to asking questions for future reference.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Requesting a UmbracoAuthorizedApiController resulted in a 404 error

I am encountering difficulties while attempting to make a request from a custom dashboard plugin that I have configured in Umbraco CMS version 12. Every time I call the /get/ method, I receive a 404 error in the backoffice. If you require any additional in ...

Exploring ways to use TypeScript to export a Mongoose model?

There's a module I need to export in order to avoid the error "OverwriteModelError: Cannot overwrite Task model once compiled". I've tried various solutions but none seem to work. The problem lies in the last line (export default models...) impo ...

Utilize SWR in NextJS to efficiently manage API redirection duplication

When using SWR to fetch data, I encountered an error where the default path of nextjs was repeated: http://localhost:3000/127.0.0.1:8000/api/posts/get-five-post-popular?skip=0&limit=5 Here is my tsx code: 'use client' import useSWR from &quo ...

Enhancing TypeScript builtin objects in Netbeans using a custom plugin

While in the process of converting JavaScript code to TypeScript, I encountered a challenge with extending built-in objects using Object.defineProperty, such as String.prototype. Object.defineProperty(String.prototype, 'testFunc', { value: funct ...

Configuring ag-grid in an Angular project

I'm facing an issue with setting up ag-grid in my existing Angular project. Our project currently has version 8.2.0 of ag-grid installed, without any additional dependencies like ag-grid-angular. Do I need to install extra dependencies for ag-grid sup ...

Utilizing Dual Destructuring for Handling Undefined Main Objects

Before we proceed, I want to clarify that my question is not a duplicate of ES6 double destructure Let's examine the code snippet related to Apollo Client GraphQL: import { gql, useQuery, useMutation } from '@apollo/client'; ... const { loa ...

Sending information to varying view/module - AngularJS

I am relatively new to AngularJS, so my question may seem quite basic. In one of my views, I have a link that, when clicked, calls a service to retrieve data. In the controller, I am using $location to change the view and update it with the data fetched f ...

What are the best practices for preventing risky assignments between Ref<string> and Ref<string | undefined>?

Is there a way in Typescript to prevent assigning a Ref<string> to Ref<string | undefined> when using Vue's ref function to create typed Ref objects? Example When trying to assign undefined to a Ref<string>, an error is expected: co ...

The method of having two consecutive subscribe calls in Angular2 Http

Can the Subscribe method be called twice? I am attempting to create an API factory that stores data in the factory and allows different components to use that data for each AJAX call. The factory: export class api { result = []; constructor (p ...

Conditionally displaying a select element using Ng-if

Is there a way to display content based on the user's selection in an HTML form? Here is how I attempted to do it: <select class="form-control" id="Intervencion" > <option selected disabled></option> <option (click)="show ...

The functionality of the disabled and checked options on the radio button seems to be malfunction

Within an Angular HTML document, I have a set of radio buttons that share common names. I am attempting to update their disabled and checked properties from a .ts file, but the changes are not taking effect. Here is the code snippet: let elements = docume ...

What is the most effective way to eliminate all values in an object key array except for one specific value?

Currently, I am developing an angular project and have encountered an object with the following structure: const obj = { fruits: ['apple', 'orange', 'None'], nation: ['usa'], city: ['New York', ' ...

Securing a definitive URL for a web application hosted on Azure Static Web App for long-term use

Currently, I am in the process of developing an Azure-based application. The setup I have so far consists of: The frontend being Angular v16 and hosted on an Azure Static Web Site (running on Linux) The backend utilizing an ASP.NET Core 7 Web API hosted i ...

What is the best way to extract multiple records from an Array?

Below is a simple filter function that filters Rec_pagedItems in an array called allItems. someval(value){ if(value.length>=5){ this._pagedItems= this.allItems.find(e=>e.uniqueid == value || e.name == value ); if(this._pagedItem ...

The module 'primeng/utils' does not contain the export 'FilterUtils'

Recently, I upgraded Angular to version 15 and encountered an error: The module ""primeng/utils"" does not have an exported member called 'FilterUtils'. Is there a way to implement filtering similar to this without making changes to ...

Is there a way to eliminate the hover effect on a button within a navbar?

I'm currently working on a website using Angular and I have implemented a gray navbar with a hamburger icon that reveals a dropdown menu upon clicking. One of the menu items is "Projects," which when hovered over, displays individual links to various ...

The term 'router-outlet' is unrecognized in Angular 2

After creating a brand new Angular project using the Angular CLI and setting up a new route, I encountered an error message: 'router-outlet' is not a recognized element Could someone offer some assistance with this issue? ...

Guide on correctly importing the Monaco IStandaloneCodeEditor interface in Vue3 using the Composition API

While working with Monaco, I came across a challenge in defining the instance type for encapsulating a component package. I am unsure about how to import the interface IStandaloneCodeEditor | IStandaloneDiffEditor, or if it is necessary at all. <script ...

Why does Material-UI's "withStyles()" not function properly with a specified constructor in Typescript?

Update: Please note that there was an issue with the constructor generated by IntelliJ IDEA, but it has been fixed. You can find more details here: I'm exploring the use of Material-UI in my application, and I've encountered some challenges wit ...

Adding a unique prefix for Angular2 routes in various environments

Imagine you are working on an Angular2 application in the development phase, and it is currently running smoothly on localhost:3000. All the routes are functioning properly. However, for deployment on myserver.com/myapp/, you need to add a prefix of myapp ...