Do you call AngularJS services from your Kendo datasource?
Updated by Brady Stroud [SSW] 6 months ago. See history
The bad way to call your API from a Kendo datasource with AngularJS. Notice the hard coded url directly calling the API endpoint.
read: {url: "../content/dataviz/js/spain-electricity.json",dataType: "json"}
❌ Figure: 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.
module app.widgets {'use strict';class AssetAllocationByAssetClassChartController {isLoading: any;static $inject = ['app.dataServices.InvestmentReportsService']constructor(private investmentReportsService: dataServices.InvestmentReportsService) { }options = {series: [{field: 'AssetStrategyOverallPercent',categoryField: 'AssetClassName'}],seriesDefaults: {type: 'pie'},legend: {position: 'bottom',labels: {visible: true,background: 'transparent',template: '#=text # #=value#% '}},dataSource: new kendo.data.DataSource({transport: {read: (promise: any) => {this.getFundAssetPositionChartData(promise);}}})}getFundAssetPositionChartData = (promise) => {this.isLoading = true;return this.investmentReportsService.fundAssetPosition().then((response) => {promise.success(response.Data.PortfolioAssetPositions[0].AssetClassDetailList);this.isLoading = false;});}}Angular.module('app.widgets').controller('app.widgets.assetAllocationByAssetClassChartController',AssetAllocationByAssetClassChartController)}
✅ Figure: Good Example - This code passes a promise to a function which calls an AngularJS service to call the API endpoint.
Need help?
SSW Consulting has over 30 years of experience developing awesome software solutions.