I have below code in Angularjs javascript file which is powering d3js radar chart
chart.js
ui.d3.TsPlot = function(element) {
this._element = element;
this._plotRadius = 41;
this._padding = 7;
this._interpolation = 'linear-closed';
this._editable = false;
this._tooltips = true;
this._animated = true;
this._freeDraw = false;
this._exps = [];
.........
};
ui.tsplot = function() {
function link(scope, element, attrs) {
var tsPlot = new ui.d3.TsPlot(element[0])
.setPlotRadius(parseInt(attrs.plotRadius, 10))
.setInnerRadius(parseInt(attrs.innerRadius, 10))
// Some other assignments for TsPlot
}
}
angular
.module('ui.tsplot', [])
.directive('tsPlot', ui.tsplot);
I would like to call tsplot() in my javascript function in the template.
home.html
<script type="text/javascript">
function retry()
{
alert('Before assignment');
var scope = angular.element(document.getElementById("tsPlot")).scope();
scope.ui.tsplot();
alert('After assignment');
}
However second alert never runs when I invoke retry() function, when I checked the console, browser throws an error as "Uncaught TypeError: Cannot read property 'ui' of undefined"
Below code I use in my template
<script>
var app = angular.module('tsPlotExampleApp', ['ui.tsplot']);
app.controller('tsPlotCtrl', function ($scope) {
$scope.dyndata={};
});
</script>
What am I missing in retry(), what should I do to invoke ui.tsplot() in retry?
Objective of this is to load the d3 function as I have dynamically created the charts.
I have below code for my d3 chart in Angularjs javascript file. In what context isui.tsplotdefined? Can you show "the surroundings"?ui.tsplot? It doesn't look correct. It needs to return the link function.ui.tsplotfunction is the entire factory funciton that you register as yourtsPlotdirective, is that really the function you want to call? That function only returns the directive definition object. And it isn't availble as a method on the scope.