[英]How to change text in div while executing setInterval function using highcharts-ng with angularjs
I have a controller
which has the following call : 我有一个
controller
,它有以下调用:
userFactory.getScore(_token, function (response) {
$scope.scores = response;
renderCharts(response,$scope);
score.resolve();
});
here, userFactory
is a factory. 这里,
userFactory
是一个工厂。
Now in my function renderCharts
: 现在在我的
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"};
}
}
Following assignment doesn't update the value in ng-bind in the html
view : $scope.current_target_label = {"label":"Target Score"};
以下赋值不会更新
html
视图中ng-bind中的值: $scope.current_target_label = {"label":"Target Score"};
I am surely doing something wrong, appreciate for any pointers so as to what to do to get the value of text of div
updated in the html
view ? 我肯定做错了什么,欣赏任何指针,以便做什么来获得在
html
视图中更新div
的文本的价值?
setInterval
is outside of angulars $digest-cycle , so angular will not update data-bindings. setInterval
在 angulars $ digest-cycle之外 ,因此angular不会更新数据绑定。 You could use $apply
but, I'd say, that's bad practice. 你可以使用
$apply
但是,我会说,这是不好的做法。 Better use $timeout
or $interval
. 更好地使用
$timeout
或$interval
。 Wich will trigger the $digest-cycle . 这将触发$ digest-cycle 。 Eg:
例如:
function renderCharts(response,$scope) {
// ...
$interval(function() {
// Logic to update highchart
$scope.current_target_label = {"label":"Target Score"};
}, delay);
}
Notes: 笔记:
setInterval(function($scope) {
. $scope
here will probably be undefined, and thus shadow the outer $scope
variable. setInterval(function($scope) {
。 $scope
这里可能是未定义的,因此会影响外部$scope
变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.