This is a migrated thread and some comments may be shown as answers.

Angular scope variables within k-data-source

3 Answers 318 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Rajesh
Top achievements
Rank 1
Rajesh asked on 17 Aug 2014, 06:43 AM
I am trying to create a simple donut chart using Kendo UI data wiz widgets. How can I use an angular scope variable within such a widget ?

 <div kendo-chart
                     k-legend="{ position: 'top' }"
                     k-series-defaults="{ type: 'donut', startAngle: 270, holeSize: 80 }"
                     k-chart-area="{ background: '', height:220 }"
                     k-series="[{
                            field: 'share',
                            categoryField: 'resolution',
                            visibleInLegendField: 'visibleInLegend',
                            padding: 10
                          }]"
                     k-data-source="[
                        {
                            share: {{myMetadata.runningPercentage}},
                            visibleInLegend: false,
                            color: '#65c178'
                        },
                        {
                            share: 100 - {{myMetadata.runningPercentage}},
                            visibleInLegend: false,
                            color: '#e2e2e2'
                        }
                     ]"
                     k-series-hover="onSeriesHover"
              >

3 Answers, 1 is accepted

Sort by
0
Mihai
Telerik team
answered on 18 Aug 2014, 07:54 AM
Hi Rajesh,

The k-* attributes are evaluated in the current $scope, so you don't need to include the {{angular}} brackets in order to access scope data.  You can simply say:

k-data-source="[
                        {
                            share: myMetadata.runningPercentage,
                            visibleInLegend: false,
                            color: '#65c178'
                        },

although my recommendation is to move the whole definition in the scope, like this:

    k-data-source="myDataSource"

and in your controller:

    $scope.myDataSource = [ { share: $scope.myMetadata.runningPercentage ... ]

Also, note that for event handlers declared as attributes you should prefix with "k-on-", for example k-on-series-hover="onSeriesHover($kendoEvent)".

Regards,
Mihai
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Rajesh
Top achievements
Rank 1
answered on 18 Aug 2014, 05:26 PM
Thanks very much Mihai for the quick response.

Is there any reason you recommend that all of the k-options are moved to the controller. To me all k options belong only in the view and hence in the html, while the controller must ideally only have the business logic to populate the right scope variables.

The controller should not have to change if I decide to use a input instead of a kendo input. What do you feel ?
0
Accepted
Mihai
Telerik team
answered on 19 Aug 2014, 07:21 AM
Hi Rajesh,

Feel free to keep options in the markup if you so wish.  It's just a matter of preference in the end; to me it feels cleaner to keep complex options (i.e. JSON objects) in JavaScript, rather than in HTML.

Regards,
Mihai
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Mihai
Telerik team
Rajesh
Top achievements
Rank 1
Share this question
or