1

I created a directive which has a directive inside it, and when I try to give it parameters I get this message: This error message

Here is my directive

app.directive('percentageSquare', function(){
    return {
        restrict: 'E',
        scope: {
            color: '@',
            chartConfig: '@'
        },
        templateUrl: '/templates/dashboard/charts/PercentageChart.html'
    };
});

Which loads this template:

<div class="drop-shadow">
    <highchart id="{{chartConfig}}" config="{{chartConfig}}" style="background-color: {{color}};" ng-show="true"></highchart>
</div>

Here is how I am calling it:

<percentage-square color="yellow" chart-config="chartBounceRate"></percentage-square>

I am not sure what I can do to fix it, because it look just fine to me...

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338

1 Answers1

1

The way highcharts works, it want to have config to be an object from scope. so you should use two way binding here

Directive

scope: {
   color: '@',
   chartConfig: '=', //<--two way binding here
   selector: '@'
},

Directive Use

<percentage-square color="'yellow'" chart-config="chartBounceRate" selector="{{selector}}"></percentage-square>

Template

<div class="drop-shadow">
    <highchart id="{{selector}}" config="chartConfig" 
       ng-style="{background-color: color}" ng-show="true">
    </highchart>
</div>

EDIT

See this famous stackoverflow question and answer to understand @, & and = in angularjs directive definition

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299