Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
change scope.knob to var knob.
scope.knob = scope.$eval(attrs.knobData); 
to
var knob = scope.$eval(attrs.knobData);

If you name the data variable $scope.knob in the main scope than the directive will overwrite it and $watch will not function. 
An internal variable is better
  • Loading branch information
DexterMorg4n committed Oct 8, 2014
commit 76a1de5fb1008e3adb80eafd0ae4ce0b73bbe889
116 changes: 58 additions & 58 deletions src/angular-knob.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
angular.module('ui.knob', [])
.directive('knob', function () {
return {
restrict: 'EACM',
template: function(elem, attrs){

return '<input value="{{ knob }}">';

},
replace: true,
scope: true,
link: function (scope, elem, attrs) {

scope.knob = scope.$eval(attrs.knobData);
var $elem = angular.element(elem);

var renderKnob = function(){

scope.knob = scope.$eval(attrs.knobData);

var opts = {};
if(!angular.isUndefined(attrs.knobOptions)){
opts = scope.$eval(attrs.knobOptions);
}

if(!angular.isUndefined(attrs.knobMax)){
var max = scope.$eval(attrs.knobMax);
if(!angular.isUndefined(max)){

opts.max = max;

}
}
angular.element(elem).knob(opts);
};

var updateMax = function updateMax() {
var max = scope.$eval(attrs.knobMax);
var val = scope.$eval(attrs.knobData);
$elem.trigger('configure', {
'max': parseInt(max, 10)
}).trigger('change');
$elem.val(val).change();
return {
restrict: 'EACM',
template: function(elem, attrs){

return '<input value="{{ knob }}">';

},
replace: true,
scope: true,
link: function (scope, elem, attrs) {

var knob = scope.$eval(attrs.knobData);
var $elem = angular.element(elem);

var renderKnob = function(){
console.log('render')
knob = scope.$eval(attrs.knobData);

var opts = {};
if(!angular.isUndefined(attrs.knobOptions)){
opts = scope.$eval(attrs.knobOptions);
}

if(!angular.isUndefined(attrs.knobMax)){
var max = scope.$eval(attrs.knobMax);
if(!angular.isUndefined(max)){

opts.max = max;

}
}
angular.element(elem).knob(opts);
};

var updateMax = function updateMax() {
var max = scope.$eval(attrs.knobMax);
var val = scope.$eval(attrs.knobData);
$elem.trigger('configure', {
'max': parseInt(max, 10)
}).trigger('change');
$elem.val(val).change();
};

scope.$watch(attrs.knobData, function () {
knob = scope.$eval(attrs.knobData);
$elem.val(knob).change();
});

scope.$watch(attrs.knobMax, function() {
updateMax();
});

scope.$watch(attrs.knobOptions, function () {
elem.trigger('configure',scope.$eval(attrs.knobOptions));
renderKnob();
}, true);

}
};

scope.$watch(attrs.knobData, function () {
scope.knob = scope.$eval(attrs.knobData);
$elem.val(scope.knob).change();
});

scope.$watch(attrs.knobMax, function() {
updateMax();
});

scope.$watch(attrs.knobOptions, function () {
elem.trigger('configure',scope.$eval(attrs.knobOptions));
renderKnob();
}, true);

}
};
});