0

I am still learning the Angular ropes and would like some guidance on the following...

I have several KendoUI-related data source definitions that I would like to reuse in various AngularJS controllers.

Currently in one controller, I have:

var dataSource = new kendo.data.DataSource({ ... });

Since I will have a few data sources, I can place them in something like a globalFunctions.js file:

var dataSource1 = new kendo.data.DataSource({ ... });
var dataSource2 = new kendo.data.DataSource({ ... });
var dataSource3 = new kendo.data.DataSource({ ... });

Then get an instance of the required data source from within my Angular controller.

Since I don't want to load up all data sources for each page (or even need them to be available), would it be better to create a separate data source file for each data source, then inject 1..* into whichever controller needs them, and new-up as needed?

I would like to know the 'proper' way of implementing this with AngularJS.

ElHaix
  • 12,846
  • 27
  • 115
  • 203
  • Usually, data sources of this kind are new'd up as needed. Global objects of the kind you describe are sort of an antipattern, although you could certainly put the common ones in a js and call them as needed to new up a data source. What does Telerik recommend? – Robert Harvey Mar 03 '14 at 19:10
  • KendoUI datasources are JS objects that can be shared. I'd like to know the recommended *AngularWay*. This is more about object reuse/sharing. – ElHaix Mar 03 '14 at 19:15
  • Have you seen this? http://kendo-labs.github.io/angular-kendo/#/ – Robert Harvey Mar 03 '14 at 19:21
  • I'm not familiar with Kendo, but it seem like making each data source a service might be the way to go, especially if they are singletons. – Craig Squire Mar 03 '14 at 19:25

1 Answers1

0

Use a service to share data between controllers.

Community
  • 1
  • 1
jingman
  • 415
  • 3
  • 10