Skip to content

Commit 9c8a515

Browse files
author
Brian Hines
committed
Merge pull request #3 from juanpasolano/master
watch for changes on data
2 parents 36f52dc + 49820ef commit 9c8a515

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

angular-peity.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,37 @@ var buildChartDirective = function ( chartType ) {
1010
},
1111
link: function ( scope, element, attrs ) {
1212

13-
var options = {};
14-
if ( scope.options ) {
15-
options = scope.options;
16-
}
13+
var options = {};
14+
if ( scope.options ) {
15+
options = scope.options;
16+
}
1717

18-
var span = document.createElement( 'span' );
19-
span.textContent = scope.data.join();
18+
var span = document.createElement( 'span' );
19+
span.textContent = scope.data.join();
20+
21+
if ( !attrs.class ) {
22+
span.className = "";
23+
} else {
24+
span.className = attrs.class;
25+
}
2026

21-
if ( !attrs.class ) {
22-
span.className = "";
23-
} else {
24-
span.className = attrs.class;
25-
}
27+
if (element[0].nodeType === 8) {
28+
element.replaceWith( span );
29+
} else {
30+
element[0].appendChild( span );
31+
}
32+
33+
jQuery( span ).peity( chartType, options );
34+
35+
var watcher = scope.$watch('data', function(){
36+
span.textContent = scope.data.join();
37+
jQuery( span ).change();
38+
})
2639

27-
if (element[0].nodeType === 8) {
28-
element.replaceWith( span );
29-
} else {
30-
element[0].appendChild( span );
31-
}
40+
scope.$on('$destroy', function(){
41+
watcher();
42+
});
3243

33-
jQuery( span ).peity( chartType, options );
3444

3545
}
3646
};

0 commit comments

Comments
 (0)