UNPKG

1.23 kBPlain TextView Raw
1import {Grid, GridParams} from "../grid";
2
3export function initialiseAgGridWithAngular1(angular: any) {
4 let angularModule = angular.module("agGrid", []);
5 angularModule.directive("agGrid", function() {
6 return {
7 restrict: "A",
8 controller: ['$element', '$scope', '$compile', '$attrs', AngularDirectiveController],
9 scope: true
10 };
11 });
12}
13
14function AngularDirectiveController($element: any, $scope: any, $compile: any, $attrs: any) {
15 let gridOptions: any;
16 let quickFilterOnScope: any;
17
18 let keyOfGridInScope = $attrs.agGrid;
19 quickFilterOnScope = keyOfGridInScope + '.quickFilterText';
20 gridOptions = $scope.$eval(keyOfGridInScope);
21 if (!gridOptions) {
22 console.warn("WARNING - grid options for ag-Grid not found. Please ensure the attribute ag-grid points to a valid object on the scope");
23 return;
24 }
25
26 let eGridDiv = $element[0];
27 let gridParams: GridParams = {
28 $scope: $scope,
29 $compile: $compile,
30 quickFilterOnScope: quickFilterOnScope
31 };
32 let grid = new Grid(eGridDiv, gridOptions, gridParams);
33
34 $scope.$on("$destroy", function() {
35 grid.destroy();
36 grid = null;
37 });
38}