Skip to content

Commit

Permalink
watch for changes on data
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpasolano committed Apr 7, 2016
1 parent 36f52dc commit 49820ef
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions angular-peity.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,37 @@ var buildChartDirective = function ( chartType ) {
},
link: function ( scope, element, attrs ) {

var options = {};
if ( scope.options ) {
options = scope.options;
}
var options = {};
if ( scope.options ) {
options = scope.options;
}

var span = document.createElement( 'span' );
span.textContent = scope.data.join();
var span = document.createElement( 'span' );
span.textContent = scope.data.join();

if ( !attrs.class ) {
span.className = "";
} else {
span.className = attrs.class;
}

if ( !attrs.class ) {
span.className = "";
} else {
span.className = attrs.class;
}
if (element[0].nodeType === 8) {
element.replaceWith( span );
} else {
element[0].appendChild( span );
}

jQuery( span ).peity( chartType, options );

var watcher = scope.$watch('data', function(){
span.textContent = scope.data.join();
jQuery( span ).change();
})

if (element[0].nodeType === 8) {
element.replaceWith( span );
} else {
element[0].appendChild( span );
}
scope.$on('$destroy', function(){
watcher();
});

jQuery( span ).peity( chartType, options );

}
};
Expand Down

0 comments on commit 49820ef

Please sign in to comment.