Angular 财产';地图';不存在于类型';地图页';
我正在尝试将谷歌地图插入到我的基于Tabs模板的Ionic 2应用程序中 在我尝试初始化构造函数这个.map方法之前,一切都很正常Angular 财产';地图';不存在于类型';地图页';,angular,typescript,ionic2,ionic3,Angular,Typescript,Ionic2,Ionic3,我正在尝试将谷歌地图插入到我的基于Tabs模板的Ionic 2应用程序中 在我尝试初始化构造函数这个.map方法之前,一切都很正常 import {Component} from '@angular/core'; import {Geolocation} from 'ionic-native'; import {NavController} from 'ionic-angular'; @Component({ templateUrl: 'build/pages/map/map.html'
import {Component} from '@angular/core';
import {Geolocation} from 'ionic-native';
import {NavController} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/map/map.html'
})
export class MapPage {
constructor(private navCtrl: NavController) {
this.map = null;
this.loadMap();
}
loadMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8
});
}
}
现在控制台抛出一个错误GET
我的终端也有一个错误:
错误TS2339:类型“MapPage”上不存在属性“map”
发现许多类似的情况,出现问题错误TS2339:类型“Observable”上不存在属性“map”
我已经更新了我的npm-没有帮助。
从我的代码中删除this.map=null方法不会使我的应用程序工作,同样的错误和ionic serve命令不会加载我的应用程序(仅其默认index.html页面)
如何将属性“map”添加到我的“MapPage”类中以解决此问题?我的代码中有什么地方出错了?在使用它之前,您需要声明
map
属性:
import {Component} from '@angular/core';
import {Geolocation} from 'ionic-native';
import {NavController} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/map/map.html'
})
export class MapPage {
private map: any; // <- declare the variable
constructor(private navCtrl: NavController) {
this.map = null; // <- Now the variable exists so you can initialize it
this.loadMap();
}
loadMap() {
// Instead of using a new variable, use this.map to use the existing map property
this.map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8
});
}
}
从'@angular/core'导入{Component};
从“ionic native”导入{Geolocation};
从'ionic angular'导入{NavController};
@组成部分({
templateUrl:'build/pages/map/map.html'
})
导出类映射页{
私有映射:any;//在使用它之前,您需要声明map
属性:
import {Component} from '@angular/core';
import {Geolocation} from 'ionic-native';
import {NavController} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/map/map.html'
})
export class MapPage {
private map: any; // <- declare the variable
constructor(private navCtrl: NavController) {
this.map = null; // <- Now the variable exists so you can initialize it
this.loadMap();
}
loadMap() {
// Instead of using a new variable, use this.map to use the existing map property
this.map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: false,
zoom: 8
});
}
}
从'@angular/core'导入{Component};
从“ionic native”导入{Geolocation};
从'ionic angular'导入{NavController};
@组成部分({
templateUrl:'build/pages/map/map.html'
})
导出类映射页{
私人地图:任何//