Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
---
archivedreason: null
type: rule
title: Do you call AngularJS services from your Kendo datasource?
uri: do-you-call-angularjs-services-from-your-kendo-datasource
categories:
- category: categories/software-engineering/rules-to-better-angularjs.mdx
- category: categories/software-engineering/rules-to-better-kendo-ui.mdx
authors:
- title: Duncan Hunter
url: https://ssw.com.au/people/duncan-hunter
created: 2015-05-05 19:33:05+00:00
- title: Duncan Hunter
url: 'https://ssw.com.au/people/duncan-hunter'
redirects: []
guid: 1da148fe-4093-419d-b4b0-4cc50f50d36b
seoDescription: >-
Learn how to properly integrate AngularJS services with Kendo DataSource for
cleaner code and better maintainability.
created: 2015-05-05T19:33:05.000Z
createdBy: Tiago Araujo
createdByEmail: TiagoAraujo@ssw.com.au
guid: 1da148fe-4093-419d-b4b0-4cc50f50d36b
isArchived: false
lastUpdated: 2021-03-17 05:22:32.290000+00:00
lastUpdated: 2021-03-17T05:22:32.290Z
lastUpdatedBy: Jack Leerson
lastUpdatedByEmail: 77082983+JackLeerson@users.noreply.github.com
redirects: []
seoDescription: Learn how to properly integrate AngularJS services with Kendo DataSource
for cleaner code and better maintainability.
title: Do you call AngularJS services from your Kendo datasource?
categories:
- category: categories/software-engineering/rules-to-better-angularjs.mdx
- category: categories/software-engineering/rules-to-better-kendo-ui.mdx
type: rule
uri: do-you-call-angularjs-services-from-your-kendo-datasource
isArchived: false
archivedreason: null
---

To keep a good separation of concerns between your AngularJS controllers and your data service layers you should always call an AngularJS service or factory from your Kendo datasource logic.
Expand All @@ -30,7 +31,7 @@ Many demonstrations show a hard coded string in your Angular controllers calling
2. Your controllers will be harder to unit test
3. If you want to call the same API endpoint somewhere else in your application you now have two place with this hard coded string, that might need to change in the future
4. If you keep all your data calls in one place your code will be easier to read and you can share business logic for making the API calls within your Angular service or factory, like a common error handling message for failed API calls
5. Finally you can perform actions while the promise is being resolved, like show a spinner animation or log out a message to the user
5. Finally you can perform actions while the promise is being resolved, like show a spinner animation or show a message to the user

<endIntro />

Expand All @@ -42,7 +43,8 @@ read: {
dataType: "json"
}
```
**❌ Bad Example - This hard codes your url endpoint throughout your application**

**❌ Bad Example - This hard codes your url endpoint throughout your application**

This is example is in TypeScript and you can see the Kendo data source is calling the getFundAssetPositionChartData function and passing it a promise which when resolved will return the data. This function calls an AngularJS service which then calls the API endpoint. You can also see in the getFundAssetPositionChartData function the ‘this.isLoading = true’ code which is turning the pages spinner feature on and off when the call is resolved, to let the user know it is processing.

Expand Down Expand Up @@ -98,4 +100,5 @@ module app.widgets {
)
}
```
**✅ Good Example - This code passes a promise to a function which calls an AngularJS service to call the API endpoint.**

**✅ Good Example - This code passes a promise to a function which calls an AngularJS service to call the API endpoint.**
Loading