score:6

Accepted answer

put an if control in your watch to check if your data item is ready to go or not

directives.directive('d3Bar', [function() {
    return {
        restrict : 'E',
        scope : {
            data : '='
        },
        link : function(scope, element) {
            scope.$watch('data', function(newData, oldData) {
                if(newData){
                    drawLine(newData);
                }
            }, true);
        }
    }
}])

score:9

Use ng-if with your condition that data is available or not, to resolve this problem.

HTML:

<body ng-controller='MainCtrl'>
  <div ng-if="d3Data">
    <d3-bar data='d3Data'></d3-bar>
  <div>
</body>

So your directive will load only when d3Data has any data.


Related Query

More Query from same tag