The $ parse service takes an expression and turns it into a function that will resolve the actual data while providing a context, which is usually a scope.
var exp = $parse(attrs.chartData);
Just look at salesDataToPlot ( pen ):
scope.salesDataToPlot = salesDataToPlot; scope.$watchCollection('salesDataToPlot', function(newVal, oldVal){ salesDataToPlot=newVal; redrawLineChart(); });
Using salesData directly causes an error, because salesData is a property in scope, not a variable, available in this closure. To make $ watchCollection look for this property in scope, you will have to use "salesData" ( pen ).
scope.$watchCollection("salesData", function(newVal, oldVal){ salesDataToPlot=newVal; redrawLineChart(); });
source share