Skip to content

Instantly share code, notes, and snippets.

@meatballs
Last active August 29, 2015 14:12
Show Gist options
  • Save meatballs/94d7839275461185f5c4 to your computer and use it in GitHub Desktop.
Save meatballs/94d7839275461185f5c4 to your computer and use it in GitHub Desktop.
PivotTable with AngularJS Directive and CoffeeScript
'use strict'
app = angular.module('app')
class PivotCtrl
@$inject = [
'$scope'
'pivotService'
]
constructor: ($scope, pivotService) ->
@pivotService = pivotService
app.controller 'PivotCtrl', PivotCtrl
'use strict'
app = angular.module('app')
app.directive 'pivotTable', ->
scope: { datasource: '=' },
link: (scope, element, attrs) ->
scope.datasource.$promise.then (result) ->
$(element).pivotUI(
result,
scope.$eval(attrs.pivotTable))
How to use pivottable with an AngularJS directive in coffeescript
'use strict'
app = angular.module('app')
class PivotService
@$inject = ['$resource']
constructor: ($resource) ->
url = 'http:// whatever the rest of the url might be'
resource = $resource url, null, {query: {timeout: 5000, isArray: true}}
@pivotData = resource.query(
(data) ->
# do something here on success if necessary
return
(response) =>
# do something here on failure if necessary
)
app.service 'pivotService', PivotService
<section ng-controller="PivotCtrl as ctrl">
<div class="panel panel-default">
<div datasource="ctrl.pivotService.pivotData" pivot-table="{rows: [], cols: [], vals: [], rendererName: 'Table'}"></div>
</div>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment