所以我正在尝试将谷歌地图导入我的 ionic 2 应用程序。到目前为止,一切正常。我从@angular/核心导入 VeiwChild 包时出现问题。因此,每次我运行代码时,它都会给我相同的错误。
模块"C:/Users/Jay/Documents/maps/node_modules/@angular/core/core"没有导出的成员"VeiwChild"。
C:/Users/Jay/Documents/maps/src/pages/home/home.ts
从"@angular/核心"导入 { 组件,VeiwChild };
从"ionic-angular"导入 { 导航控制器 }
;这是我的索引.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Ionic App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#4e8ef7">
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<script src="cordova.js"></script>
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.error('Error', err));
}
</script>-->
<link href="build/main.css" rel="stylesheet">
</head>
<body>
<!-- Ionic's root component and where the app will load -->
<ion-app></ion-app>
<script src="http://maps.google.com/maps/api/js?key=AIzaSyB0i4Rwgm2oyIOevkQNPydd1BwXJOV2WBk"></script>
<!-- The polyfills js is generated during the build process -->
<script src="build/polyfills.js"></script>
<!-- The bundle js is generated during the build process -->
<script src="build/main.js"></script>
</body>
</html>
这是家.html代码
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div #map id="map"></div>
</ion-content>
这是我的家.scss代码
page-home {
.ios, .md {
home-page {
.scroll {
height: 100%
}
#map {
width: 100%;
height: 100%;
}
}
}
}
最后这是我的家.ts代码
import { Component, VeiwChild } from '@angular/core';
import { NavController } from 'ionic-angular';
declare var google;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@VeiwChild('map') mapElement;
map: any;
constructor(public navCtrl: NavController) {
}
ionVeiwDidLoad()
{
this.loadMap();
}
loadMap(){
let latLng = new google.maps.LatLng(-34.9290, 138.6010);
let mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
}
}
我不完全确定为什么我总是收到此错误。这是我用作参考的视频。 链接
这只是一个错字。
这:
import { Component, VeiwChild } from '@angular/core';
应该是这样的:
import { Component, ViewChild } from '@angular/core';
View
不Veiw
注意:在其他几个地方也拼写错误,例如这里:
@VeiwChild('map') mapElement;