1

We using trying to use the ag-grid 14.0.0 in our application (AngularJS 1.5 based).

We have this snippets of codes

main.js

import angular from 'angular';
import angularUiRouter from '@uirouter/angularjs';
import angularUiBootstrap from 'angular-ui-bootstrap';
import angularSanitize from 'angular-sanitize';
import agGrid from 'ag-grid/dist/ag-grid';
import appModule from './app/app.module';
import './styles/app.less';


angular
  .module('main', [
    angularUiRouter,
    angularUiBootstrap,
    angularSanitize,
    appModule,
    agGrid
  ]);

app.module.js

import angular from 'angular';
import appComponent from './app.component';
....
....
....
import contestantsModule from './contestants/contestants.module';

/* @ngInject */
const defaultRouteConfig = ($stateProvider, $locationProvider, $urlRouterProvider) => {
  $locationProvider.html5Mode(true);
  $urlRouterProvider.otherwise('/home');
};

export default angular
  .module('app', [
    ....
.....
.....
.....,
    contestantsModule
  ])
  .config(defaultRouteConfig)
  .component('app', appComponent)
  .name;

contestants.module.js

import angular from 'angular';
import ContestantsComponent from './contestants.component';
import agGrid from 'ag-grid/dist/ag-grid';

/* @ngInject */
initialiseAgGridWithAngular1(angular);
const routing = ($stateProvider) => {
  $stateProvider.state('contestants', {
    url: '/contestants',
    template: '<contestants></contestants>'
  });
};

export default angular.module('app.contestants', ['agGrid'])
  .config(routing)
  .component('contestants', ContestantsComponent)
  .controller('ContestantsController', ['$scope', '$http', function($scope, $http) {

  }]).name;

contestants.component.js

class ContestantsComponent {
  /* @ngInject */

  constructor($scope, $http) {
    this.$scope = $scope;
    this.$http = $http;
    console.log('inside Constructor() contestants.component.js:::');
  }


  $onInit() {
    var columnDefs = [
      {headerName: "Make", field: "make"},
      {headerName: "Model", field: "model"},
      {headerName: "Price", field: "price"}
    ];

    var rowData = [
      {make: "Toyota", model: "Celica", price: 35000},
      {make: "Ford", model: "Mondeo", price: 32000},
      {make: "Porsche", model: "Boxter", price: 72000}
    ];

    this.$scope.gridOptions = {
      columnDefs: columnDefs,
      rowData: rowData
    };
    console.log('inside onInit grid.component.js:::');
  }

}

export default {
  template: require('./contestants.component.html'),
  controller: ContestantsComponent
};

contestants.component.html

<div class="container-fluid">
  <h2>HERE</h2>
  <div ag-grid="gridOptions" class="ag-theme-fresh" style="height: 100%;"></div>
</div>

Right after trying that one we have this error:

angular.js:116Uncaught Error: [$injector:modulerr] Failed to instantiate module main due to: Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module app.contestants due to: Error: [$injector:modulerr] Failed to instantiate module {"DragSourceType":{"0":"ToolPanel","1":"HeaderCell","ToolPanel":0,"HeaderCell":1},"HDirection":{"0":"Left","1":"Right","Left":0,"Right":1},"VDirection":{"0":"Up","1":"Down","Up":0,"Down":1},"RowType":{"0":"HEADER_GROUPING","1":"HEADER","2":"BODY","HEADER_GROUPING":0,"HEADER":1,"BODY":2}} due to: Error: [ng:areq] Argument 'module' is not a function, got Object http://errors.angularjs.org/1.6.6/ng/areq?p0=module&p1=not%20a%20function%2C%20got%20Object

1 Answer 1

2

Try to load ag-grid like this:

import {initialiseAgGridWithAngular1} from 'ag-grid/main';

initialiseAgGridWithAngular1(angular);

angular.module(MODULE_NAME, [
    'agGrid'
])
Sign up to request clarification or add additional context in comments.

4 Comments

I am facing a different issue when i deploy it in our dev environment.codeangular.js:116 Uncaught Error: [$injector:modulerr] Failed to instantiate module main due to: Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module app.contestants due to: Error: [$injector:unpr] Unknown provider: e errors.angularjs.org/1.6.6/$injector/unpr?p0=ecode
Damn... I've not made a deploy of this app yet. How about: import agGrid from 'ag-grid/main'; agGrid.initialiseAgGridWithAngular1(angular)
Correct me if i am mistaken. Version 14.2.0, we do not have the agGrid Object in 'ag-grid/main', but i could see it in 'ag-grid/dist/ag-grid'
I use free ag-grid 16.0.1 but as I said I have not made a deploy yet, the project is halted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.