我需要更新回调函数内部的阵列对象,我使用的下面的行,但这些值是以回叫环不是作为角度变量,这样的范围设定我(deviceval)如果我在回调中打印它的值,它的值会发生变化,但是在值之外仍然是旧的。没能获得角度2范围内回叫功能
export class DashboardComponent implements OnInit {
hideTable: boolean = true;
public deviceVal:any;
constructor(private ref: ChangeDetectorRef) {}
ngOnInit() {
this.deviceVal = deviceData;
console.log(this.deviceVal);
var container = $('.map-canvas');
var options = {
center: new google.maps.LatLng(41.676258, -99.683199),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
gmap = new google.maps.Map(container[0], options);
this.drawChart(deviceData);
this.plotMarkers();
}
plotMarkers(){
$.each(deviceData, function(key, val) {
var controller=this;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(parseInt(val.lat), parseInt(val.lon)),
map: gmap,
});
google.maps.event.addListener(marker, 'click', function() {
this.deviceVal = val;
});
markerCache.push(marker);
})
}
}
我想你应该使用'$ scope。$ apply()'无论你使用的是非角度回调来告诉角度运行一个变化检测cy CLE。 – Abdel
我不认为这是唯一的问题,你的指针也是不正确的。你正在分配回调中的this参考(类的)。我想你的意思是把回调以上,使其指向正确的'''this.deviceVal''' – Abdel
@Abdel存在角2 –