RadMie / ng-knob

Angular.js directive to Knob component powered by d3.js (without jQuery)
http://radmie.github.io/ng-knob
MIT License
117 stars 48 forks source link

Not able to display updated value #34

Closed parmindersingh1 closed 7 years ago

parmindersingh1 commented 8 years ago

I am trying to fetch value from server but its sometimes not updating knob

$scope.value= 0; $http.post(link).then(function (res){

$timeout(function() { $scope.value = res.value; },1000);

});

tavurth commented 8 years ago

Same problem here, any fix for this @parmindersingh1?

tavurth commented 8 years ago

Ok, I've fixed it, replace this code:

scope.$watch("value", function(newValue, oldValue) {
    if ((newValue !== null || typeof newValue !== "undefined") && typeof oldValue !== "undefined" && newValue !== oldValue) {
        knob.setValue(newValue);
    }
});

With this patch:

var oldValue = scope.value;
scope.$watch("value", function(newValue) {
    if ((newValue !== null || typeof newValue !== "undefined") && typeof oldValue !== "undefined" && newValue !== oldValue) {
        knob.setValue(newValue);
        oldValue = newValue;
    }
});

On line 353 of ng-knob.js, then import ng-knob.js instead of the minified version.

gsfitis commented 7 years ago

I found out that by doing the following

scope.$watch("value", function(newValue, oldValue) {
    if ((newValue !== null || typeof newValue !== "undefined") && typeof oldValue !== "undefined" && newValue !== oldValue) {
        knob.setValue(newValue);
        drawKnob();
    }
});

you can fix this issue as well.

What is your opinion? Is it preferable?

noahhai commented 7 years ago

Thanks @Nuxciel worked for me.

Tusharbalar commented 7 years ago

How can i import knob ???