2017-06-13 64 views
3

我试图让Angular's UI电网运行和使用下面的代码:角/ UI的网格(NG-格)/角没有定义

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 { 
} 

使用NPM开始,我总是得到出现以下错误:

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) 

我该怎么办?谢谢!

回答

2

正如你can see

UI-Grid is currently compatible with Angular versions ranging from 1.4.x to 1.6.x.

正试图在角2 +使用它...

2

ktretyak是正确的。 UI-Grid仅由AngularJS正式支持,而不是Angular 2+。幸运的是你有选择。首先,您可能可以使其工作。例如,This github repo声称是在Angular 2+中工作的UI-Grid的一个例子。如果您愿意等待,开发团队会为Angular 5+做have a plan to upgrade UI-Grid

但是,现在找到一个在Angular 2+上正式支持的库可能是个好主意。通过UI-Grid站点上的this discussion阅读,您可以看到几个与Angular 2+兼容的数据网格。

  • 如果您已经采用了棱角分明材料,他们有一个mat-table
  • ngx-datatable是用于呈现大型和复杂数据的角度成分。它具有您希望从其他任何表中获得的所有功能,但是在没有外部依赖关系的轻型软件包中。 (来自github页面)
  • PrimeNG为Angular 2+创建了一组UI组件。他们是开源的,on github,他们有一个漂亮的光滑datatable
  • ag-grid根据他们的网站使“世界上最好的HTML 5网格”。他们有a version适用于Angular 2+。他们有免费增值模式,但他们的免费版本看起来不错。
  • angular2-datatable是另一个开源的选项,当然,它正式支持Angular 2+。

因此,不要强调自己试图在图书馆里苦苦寻觅,而这些图书馆并非真正按照自己的意愿去做。使用与Angular 2+配合使用的设备要容易得多。