【问题标题】:Angular/ Ui-Grid (ng-grid) / angular is not definedAngular/Ui-Grid(ng-grid)/角度未定义
【发布时间】:2017-06-13 12:23:08
【问题描述】:

我正在尝试让 Angular 的 ui-grid 运行并使用以下代码:

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 start 时,总是出现以下错误:

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)

我该怎么办?谢谢!

【问题讨论】:

    标签: javascript node.js angular


    【解决方案1】:

    如你can see:

    UI-Grid 目前兼容 Angular 1.4.x 到 1.6.x 的版本。

    您正在尝试在 Angular 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+ 兼容的多个数据网格。

      • 如果您已经在使用 Angular 材质,他们有一个 mat-table
      • ngx-datatable 是一个 Angular 组件,用于呈现大而复杂的数据。它具有您期望从任何其他表中获得的所有功能,但在没有外部依赖项的轻量级包中。 (来自 github 页面)
      • PrimeNG 为 Angular 2+ 制作了一组 UI 组件。他们是开源的,on github,他们有一个非常漂亮的datatable
      • ag-grid 根据他们的网站制作了“世界上最好的 HTML 5 网格”。他们有 a version 与 Angular 2+ 一起使用。他们有免费增值模式,但他们的免费版本看起来不错。
      • angular2-datatable 是另一个开源选项,当然,它正式支持 Angular 2+。

      所以,不要给自己压力,试图在一个并非真正为做你想做的事而构建的库中硬生生。使用专为 Angular 2+ 设计的软件要容易得多。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-19
        • 2016-04-15
        • 2017-07-11
        • 1970-01-01
        • 1970-01-01
        • 2013-10-06
        • 1970-01-01
        相关资源
        最近更新 更多