0

I am using AngularJS highcharts (https://github.com/pablojim/highcharts-ng)

I have this config and I need make sure it is only binded once. I looked up one-way binding on AngularJS and it says I need to use :: if I am using AngularJs 1.3(Which I am ). But I am not sure how to use it on a custom directive.

 <highchart config="configtemp"></highchart>

I tried something like but it doesn't work

 <highchart config=":: configtemp"></highchart>
Kacper Madej
  • 7,846
  • 22
  • 36
VP1456
  • 1
  • 2
  • Could you further explain what exactly "it doesn't work" means. As per my comment below, using `::` will indeed prevent the value of the attribute `config` from changing, so if the highchart directive is gathering new config data, it's not from this scope value. – Dan Apr 19 '16 at 19:45

1 Answers1

2

In this regard custom directives work the same as angular directives. AngularJS highcharts has an isolate scope as per:

scope: {
    config: '=',
    disableDataWatch: '='
  },

So it's scope will consist of the values assigned to those attributes in the html. Thus

<highchart config=":: configtemp"></highchart>

will mean that on the directive scope scope.config will be equal to ::configtemp. Since you have the '::' the value of configtemp will not change (better known as one-time binding) from it's first value as you suggested/expected. (Example of this in plunker form).

Highcharts does have some extra logic, but ultimately it's internal config is derived from this attribute/scope value.

Without further information, I cannot advise what "doesn't work".

Dan
  • 2,830
  • 19
  • 37
  • I would like to use one config for multiple charts, would it work? – VP1456 Apr 19 '16 at 21:29
  • http://jsfiddle.net/u40vs8hk/ - yes, though the chart data comes from the `series` property on the config, so if you can't set this dynamically (due to one time binding) you'd end up with the same chart twice. Hope that helps. – Dan Apr 20 '16 at 00:27
  • I'm ending up with the same chart.. i dont think it would work but thanks for help tho – VP1456 Apr 20 '16 at 13:37