SHARE
TWEET
Untitled
a guest
Oct 18th, 2016
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- // The code below is written in Typescript but I am still using Angular 1.x, not Angular 2.x
- // I don't like using $rootscope.broadcast. It feels to heavy handed. Is there a better way to pass data back from the service to the controller. Right now I have to return the "totalCount" variable. Could I be using Promises better to return control to the Controller?
- // dynamoGrapherController.ts
- namespace app {
- interface IDynamoGraph {
- dbAttributesByTable: any;
- limitCounts: number[];
- amChartOptions: any;
- showChart: boolean;
- selectedAttribute: string;
- startDateModel: Date;
- endDateModel: Date;
- resultCount: number;
- totalCount: number;
- submitGraphRequest(): void;
- }
- class DynamoGrapher implements IDynamoGraph {
- dbAttributesByTable: any;
- limitCounts: number[];
- amChartOptions: any;
- showChart: boolean;
- selectedAttribute: string;
- startDateModel: Date;
- endDateModel: Date;
- resultCount: number;
- totalCount: number;
- static $inject = ["dynamoChartService", "formOptionsService"];
- constructor(private dynamoChartService, formOptionsService) {
- this.limitCounts = formOptionsService.limitCounts;
- this.dbAttributesByTable = formOptionsService.dbAttributesByTable;
- this.amChartOptions = this.dynamoChartService.getChartOptions();
- this.showChart = this.dynamoChartService.showChart;
- this.totalCount = this.dynamoChartService.totalCount;
- }
- submitGraphRequest() {
- this.dynamoChartService.submitDynamoRequest({
- searchAttribute: this.selectedAttribute,
- startDateModel: this.startDateModel,
- endDateModel: this.endDateModel,
- limit: this.resultCount
- });
- }
- }
- angular.module("dynamoReports")
- .controller("dynamoGrapherController", DynamoGrapher);
- }
- /// from dynamoChartService.ts
- submitDynamoRequest(parameters) {
- let self = this,
- attribute = parameters.searchAttribute;
- self.$http({
- method: "POST",
- url: "/logreports-dev2/count",
- data: parameters,
- headers: {"Content-Type": "application/x-www-form-urlencoded"}
- }).then(function (response) {
- self.setCategory(attribute);
- self.setData(self.transformHashToChart(response.data, attribute));
- // self.$rootScope.$broadcast('totalCount', self.totalCount);
- self.$rootScope.$broadcast(CHART_UPDATE_DATA_EVENT, self.getChartOptions(), CHART_DOM_ID);
- self.$rootScope.$broadcast(CHART_RENDER_EVENT, self.getChartOptions(), CHART_DOM_ID);
- self.showChart = true;
- });
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
