0

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.

7
  • It isn't very clear what the following means: I have below code for my d3 chart in Angularjs javascript file. In what context is ui.tsplot defined? Can you show "the surroundings"? Commented Dec 27, 2015 at 19:40
  • Hi @tasseKATT , I have added some details in the question. Could you please check it now? Commented Dec 27, 2015 at 19:53
  • Is that really the code for ui.tsplot? It doesn't look correct. It needs to return the link function. Commented Dec 27, 2015 at 20:05
  • yea.. it was huge, so I haven't included.. its here -- return { restrict: 'E', scope: { dsn: '=', compare: '=', play: '=', stack: '=' }, link: link }; }; Commented Dec 27, 2015 at 20:06
  • The ui.tsplot function is the entire factory funciton that you register as your tsPlot directive, 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. Commented Dec 27, 2015 at 20:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.