![](/img/trans.png)
[英]How to draw multiple highcharts using highcharts-ng and angularjs
[英]How to change text in div while executing setInterval function using highcharts-ng with angularjs
我有一個controller
,它有以下調用:
userFactory.getScore(_token, function (response) {
$scope.scores = response;
renderCharts(response,$scope);
score.resolve();
});
這里, userFactory
是一個工廠。
現在在我的function renderCharts
:
function renderCharts(response,$scope) {
$scope.current_target_label = {"label":"Current Score"};
// Highcharts config object declaration here
setInterval(function($scope) {
// Logic to update highchart
$scope.current_target_label = {"label":"Target Score"};
}
}
以下賦值不會更新html
視圖中ng-bind中的值: $scope.current_target_label = {"label":"Target Score"};
我肯定做錯了什么,欣賞任何指針,以便做什么來獲得在html
視圖中更新div
的文本的價值?
setInterval
在 angulars $ digest-cycle之外 ,因此angular不會更新數據綁定。 你可以使用$apply
但是,我會說,這是不好的做法。 更好地使用$timeout
或$interval
。 這將觸發$ digest-cycle 。 例如:
function renderCharts(response,$scope) {
// ...
$interval(function() {
// Logic to update highchart
$scope.current_target_label = {"label":"Target Score"};
}, delay);
}
筆記:
setInterval(function($scope) {
。 $scope
這里可能是未定義的,因此會影響外部$scope
變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.