要让现在称为@agm/core 的angular2-google-map 正常工作,更新选择器标签 很重要。作者尚未更新文档(在帖子的这一刻)。
上次更新前:
npm install angular2-google-maps --save
<sebm-google-map [latitude]="lat" [longitude]="lng">
<sebm-google-map-marker [latitude]="lat" [longitude]="lng"></sebm-google-map-marker>
</sebm-google-map>
最新更新后现在
npm install @agm/core --save
<sebm-google-map [latitude]="lat" [longitude]="lng">
<sebm-google-map-marker [latitude]="lat" [longitude]="lng"></sebm-google-map-marker>
</sebm-google-map>
设置示例:
文件:google-maps.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-google-maps',
templateUrl: './google-maps.component.html',
styleUrls: ['./google-maps.component.css'],
})
export class GoogleMapsComponent implements OnInit {
lat: number = 51.678418;
lng: number = 7.809007;
constructor() { }
ngOnInit() {
}
}
文件:google-maps.component.html
<agm-map [latitude]="lat" [longitude]="lng">
<agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
</agm-map>
文件:google-maps.component.css
.sebm-google-map-container {
height: 300px;
}
文件:app.module.ts
import { AgmCoreModule } from '@agm/core';
@NgModule({imports: [AgmCoreModule.forRoot()}]]