Javascript AngularJS$apply有时不';当在hightchart中使用click事件时,t触发器将更新{{}}内html标记中的$scope值。
我有一个奇怪的问题 当我试图通过hightchart定义点击事件时,我使用AngularJS和HighChart:Javascript AngularJS$apply有时不';当在hightchart中使用click事件时,t触发器将更新{{}}内html标记中的$scope值。,javascript,angularjs,highcharts,Javascript,Angularjs,Highcharts,我有一个奇怪的问题 当我试图通过hightchart定义点击事件时,我使用AngularJS和HighChart: point: { events: { click: function () { $scope.currentRunId =
point: {
events: {
click: function () {
$scope.currentRunId = XXX;
$scope.showDetailModal();
}
}
}
在函数showDetailModal中,我定义:
$scope.showDetailModal = function (){
$scope.$apply(function(){
console.log($scope.currentRunId);
});
$("#detailModal").modal('show');
}
我发现尽管控制台可以正确记录$scope.currentRunId的值,html中的绑定值有时可以更新,有时不能:
<div class="modal fade" id="detailModal" tabindex="-1" role="dialog" aria-labelledby="detailModal" aria-hidden="true">
<h4 class="modal-title" id="myModalLabel">{{currentRunId}}</h4>
</div>
{{currentRunId}}
h4标记中的值有时是正确的,有时是空的,有时是缓存值。。有人能帮忙吗?我假设控制器中有$scope.showtailmodal。所以您不需要在那里调用摘要/应用方法。如果您更改了超出角度范围的内容,则必须调用摘要或应用。所以正确的代码是:
point: {
events: {
click: function () {
$scope.currentRunId = XXX;
$scope.showDetailModal();
$scope.$digest();
}
}
}
或
point: {
events: {
click: function () {
$scope.$apply(function(){
$scope.currentRunId = XXX;
$scope.showDetailModal();
});
}
}
}