Angular应用程序中的Javascript库

时间:2019-12-04 17:00:29

标签: jquery angular typescript plugins

我试图在我的angular应用程序中使用一个javascript库,但是这样做有些麻烦。

复制步骤:

  1. 使用npm安装了jquery

(npm install jquery-保存)

  1. 已安装的jquery @types

(npm install --save @ types / jquery)

  1. 在我的ts文件中,我添加了以下导入

    从'jquery'中将*导入为$;

  2. 将我要使用的库文件的位置添加到我的angular.json文件中

    “脚本”:[           “ ./node_modules/mapael/england_counties.js”,           “ ./node_modules/mapael/jquery.mapael.min.js”,           “ ./node_modules/mapael/raphael.min.js”         ]

TS文件:

import { Component, OnInit } from '@angular/core';
import * as $ from 'jquery';

@Component({
  selector: 'app-interactive-map',
  templateUrl: './interactive-map.component.html',
  styleUrls: ['./interactive-map.component.scss']
})

export class InteractiveMapComponent implements OnInit {

  constructor() { }

  ngOnInit() { 
  $(".mapcontainer").mapael(
      {
          "map": {
              "name" : "england_counties",
              "zoom": {
                  "enabled": true,
                  "maxLevel": 5
              }
          }
      })
  }   
}

我目前收到以下错误消息:

类型“ JQuery”上不存在属性“ mapael”。

任何人都可以帮忙。

0 个答案:

没有答案