我正在尝试在我的Angular项目中使用Leaflet包,但是我无法使其正常工作。
我使用npm install leatflet --save
命令安装了Leaflet,然后我在angular.json
文件中包含了它的依赖项:
"styles": [
"node_modules/leaflet/dist/leaflet.css",
],
"scripts": [
"node_modules/leaflet/dist/leaflet.js"
],
我的app.component.ts
文件:
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
constructor() {}
ngOnInit() {
const myMap = L.map('map').setView([51.505, -0.09], 13);
}
onAdressSubmit(form) {
console.log(form.value.adress);
}
}
在app.component.html
中,我有一个id为map的部分。
我只看到这个:
有人知道问题出在哪里以及如何解决吗?
非常感谢帮助。 :)