Javascript 无法设置null的属性
无法将属性“actualLocation”设置为null; 我尝试全局声明所有变量,以便可以使用后面的变量,但我不知道为什么在调用变量并尝试设置其属性时总是得到null。 我是javascript的初学者,请耐心等待 有什么想法吗 我将错误行标记为:--->Javascript 无法设置null的属性,javascript,angular,typescript,Javascript,Angular,Typescript,无法将属性“actualLocation”设置为null; 我尝试全局声明所有变量,以便可以使用后面的变量,但我不知道为什么在调用变量并尝试设置其属性时总是得到null。 我是javascript的初学者,请耐心等待 有什么想法吗 我将错误行标记为:---> 导入{ 组成部分, 奥尼特 }从“@angular/core”开始; 声明:任何; @组成部分({ 选择器:“应用程序主屏幕”, templateUrl:'./main screen.component.html', 样式URL:['./主
导入{
组成部分,
奥尼特
}从“@angular/core”开始;
声明:任何;
@组成部分({
选择器:“应用程序主屏幕”,
templateUrl:'./main screen.component.html',
样式URL:['./主屏幕.component.css']
})
导出类MainScreenComponent实现OnInit{
公开分配:任何;
公共地图:任何;
公共标记:任何;
公共电路:任何;
公共内容字符串:任意;
公共信息窗口:任何;
公共选择={
EnableHighAccurance:正确,
超时:5000,
最大值:0
};
构造函数(){}
恩戈尼尼特(){
功能成功(pos){
设crd=pos.coords;
this.actualLocation={map;
函数生成器映射(){
this.map=new google.maps.map(document.getElementById('map'){
mapTypeControl:false,
中心:{
lat:this.actualLocation.center.lat,
液化天然气:this.actualLocation.center.lng
},
缩放:15,
ZoomControl选项:{
位置:google.maps.ControlPosition.LEFT_CENTER
},
街景控制选项:{
位置:google.maps.ControlPosition.LEFT_CENTER
},
});
}
//生成标记=>标记和半径=>半径;
函数生成器markerandradius(){
this.marker=new google.maps.marker({
map:this.map,
位置:this.actualLocation.center
});
this.circleRadius=新的google.maps.Circle({
strokeColor:“#FF0000”,
笔划不透明度:0.8,
冲程重量:2,
填充颜色:'#FF0000',
不透明度:0.35,
map:this.map,
中心:this.actualLocation.center,
半径:Math.sqrt(this.actualLocation.radiusValue)*100
});
}
//生成消息=>消息;
函数generateMessage(){
这个是.contentString=
'' +
“你好”+
'';
this.infowindow=new google.maps.infowindow({
内容:this.contentString
});
this.infowindow.open(this.map,this.marker);
}
}
}
您需要使用,在这种情况下,指的是功能成功
而不是组件,请将其更改为
function success((pos) => {
let crd = pos.coords;
this.actualLocation = {
center: {
lat: crd.latitude,
lng: crd.longitude
},
radiusValue: 100
};
});
您需要使用,这种情况下指的是功能成功
而不是组件,请将其更改为
function success((pos) => {
let crd = pos.coords;
this.actualLocation = {
center: {
lat: crd.latitude,
lng: crd.longitude
},
radiusValue: 100
};
});