Angular / Ui-Grid (ng-grid) / angular is not defined
I am trying to start ui-grid Angular and use the following code:
import {NgModule} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {RouterModule} from "@angular/router";
import {BosOverviewComponent} from "./bosoverview.component";
import {UiGridModule} from 'angular-ui-grid';
@NgModule({
declarations: [
BosOverviewComponent
],
imports: [
BrowserModule,
RouterModule,
UiGridModule
],
exports: [
BosOverviewComponent
],
})
export class BusinessObjectsModule {
}
Using npm start I always get the following error:
Uncaught ReferenceError: angular is not defined
at ui-grid.js:8
at Object.../../../../angular-ui-grid/ui-grid.js (ui-grid.js:10)
at __webpack_require__ (inline.bundle.js:55)
at Object.../../../../angular-ui-grid/index.js (index.js:1)
at __webpack_require__ (inline.bundle.js:55)
at Object.../../../../../src/app/views/businessobjects/businessobjects.module.ts (bosoverview.component.ts:7)
at __webpack_require__ (inline.bundle.js:55)
at Object.../../../../../src/app/app.module.ts (app.helpers.ts:66)
at __webpack_require__ (inline.bundle.js:55)
at Object.../../../../../src/main.ts (environment.ts:8)
What should I do? Thank!
source to share
ktretyak is right. UI-Grid is only officially supported by AngularJS, not Angular 2+. Fortunately, you have options. First, you can make it work anyway. This github repo , for example, pretends to be an example of a UI-Grid working in Angular 2+. And the dev team has a plan to upgrade UI-Grid to Angular 5+ if you're willing to wait.
However, it may be a better idea to find a library that is officially supported on Angular 2+. Reading through this discussion on the UI-Grid site points out several data grids that are Angular 2+ compatible.
- If you are already using Angular Material they have mat-table
- ngx-datatable is an Angular component for representing big and complex data. It has all the features you'd expect from any other table, but in a lightweight package with no external dependencies. (from github page)
- PrimeNG creates a set of UI components for Angular 2+. They are open source, on github , and they have a nice slick datatable .
- ag-grid makes the "Best HTML 5 Grid in the World" according to their website. Their version works with Angular 2+. They have a freemium model, but their free version looks good.
- angular2-datatable is another open source option that of course officially supports Angular 2+.
So, feel free to try to rein in a library that isn't actually built to do what you want. Much easier to use the one designed to work with Angular 2+.
source to share