我需要更新回調函數內部的陣列對象,我使用的下面的行,但這些值是以回叫環不是作爲角度變量,這樣的範圍設定我(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 –