【问题标题】:Dependencies solving for GridComponent in @syncfusion/ej2-ng-grids@syncfusion/ej2-ng-grids 中 GridComponent 的依赖关系解决
【发布时间】:2017-08-11 01:32:22
【问题描述】:

我按照这个教程http://ej2.syncfusion.com/angular/documentation/grid/getting-started.html

当我运行我的项目时,JIT 遇到了这个错误

InteliSense 也显示相同的错误

我将SyncFusionModule 设置为 Angular 模块,以导出我计划在BenchmarkModule 中使用的所有“Syncfusion EJ 2 for Angular”组件。 GridComponent 在 @syncfusion/ej2-ng-grids/src/grid/index 可以被 Angular 拾取;因此,它被认为是一个 Angular 组件。但是,datasouce 没有在“GridComponent”中声明,而是在其父 Grid 中声明,这不是 Angular 组件,而是在 @syncfusion\ej2-grids 中声明的标准组件。似乎我错过了某个地方的依赖项导入,以帮助 Angular 找到 Grid 的定义。但我不确定如何解决这个问题。

一开始我以为是因为我跳过了http://ej2.syncfusion.com/angular/documentation/grid/getting-started.html#configuring-system-js中描述的SystemJS映射;因此,我提出了这个问题Webpack solution for SystemJS mapping。但是其中一个答案表明我可能不是原因。

这里是 GitHub 存储库 https://github.com/lamLeX/IocPerformance/tree/gh-pages/IocPerformanceResultWebApp/src/app,以防有人想知道文件的结构以帮助我解决依赖关系,因为我在 JS 依赖关系解决方面没有太多经验;尤其是 ES6 模块解析。

从答案更新: 故障代码取自此示例 http://ej2.syncfusion.com/angular/demos/#/grid/grouping,我已将示例代码中的错误通知 SyncFusion 团队。

<div class="control-section">
<ej-grid height="320" [datasource]="data" [groupsettings]="groupOptions" [allowgrouping]="true" allowsorting="true" allowpaging="true">
    <e-columns>
        <e-column field="Inventor" width="180" headertext="Inventor Name"></e-column>
        <e-column field="NumberofPatentFamilies" width="220" textalign="right" headertext="Number of Patent Families"></e-column>
        <e-column field="Country" width="140" headertext="Country"></e-column>
        <e-column field="Active" width="120"></e-column>
        <e-column field="Mainfieldsofinvention" width="200" headertext="Main fields of invention"></e-column>
    </e-columns>
</ej-grid>
<div style="margin-top: 10px; text-align: right">Source:
    <a href="https://en.wikipedia.org/wiki/List_of_prolific_inventors" target="_blank">Wikipedia: List of Prolific inventors</a>
</div>    
</div>

【问题讨论】:

  • 这里的 GridModule 不是 imported 在模块 github.com/lamLeX/IocPerformance/blob/gh-pages/… 中。我想这就是问题所在。对于非 Angular 组件,可能还有其他选项,但对于 Angular 组件,当缺少组件声明时会发生此错误。
  • 我尝试添加 import { Grid } from '@syncfusion/ej2-grids';在发布问题之前,但仍然出现错误
  • 并在@NgModule 中添加 Grid 以导入数组只会产生另一个错误,说 Unexpected value 'Grid' imported by the module 'SyncFusionModule'. Please add a @NgModule annotation.
  • 是的,编译器会为您进行调试。应该是import { GridModule } from '@syncfusion/ej2-grids' 和imports: [GridModule]。这应该适合你。
  • @syncfusion/ej2-grids 中没有 GridModule。 Grid 在 @syncfusion/ej2-grids 中,GridComponent 在 @syncfusion/ej2-ng-grids 中。 GridModule 是一个 Angular 模块,它在其 declarations 和 exports 数组中声明和导出 GridComponent。我尝试按照您的建议使用 `import { Grid} from '@syncfusion/ej2-grids';` 在我的SyncFusionModule 中导入 Grid,但 JIT 仍然无法找到 Grid 的属性

标签: javascript angular ecmascript-6 syncfusion es6-modules


【解决方案1】:

是ej2-ng-grids,而不是ej2-grids,和GridModule is right there。所以应该是

import { NgModule } from '@angular/core';
import { GridModule, GridComponent, PageService, SortService, FilterService, GroupService } from '@syncfusion/ej2-ng-grids';

@NgModule({
  imports: [GridModule],
  exports: [GridModule],
  declarations: [],
  providers: [PageService, SortService, FilterService, GroupService]
})
export class SyncFusionModule { }

而且没有必要这样做,因为这已经在 GridAllModule 中完成了。它应该在应用程序模块中导入,而不是自定义SyncFusionModule。

此外,上面的代码包含错误的输入 - datasource, etc.They should bedataSource` 等等, according to the documentation。

【讨论】:

  • 您的建议是否与我在这里所做的完全一致github.com/lamLeX/IocPerformance/blob/gh-pages/… 您是否尝试调用 ng serve 并在您的机器上本地尝试?
  • 我也尝试将SyncFusionModule中的所有import语句替换为GridAllModule。仍然出现同样的错误。
  • 使用 GridAllModule 时根本不需要 SyncFusionModule 之类的东西。您可能会继续收到此错误,因为它是 dataSource,而不是 datasource - groupsettings 等也是如此。幸运的是,Angular 可以检测到这些拼写错误。
  • 它有效。我知道 js 区分大小写,但我不知道它是否适用于 html 绑定:D。我选择SyncFusionModule 的原因是因为稍后我计划导出@syncfusion/ej2-ng-charts
  • 您能否更新您的答案以添加有关数据源的分辨率?非常感谢您花时间处理此案。
猜你喜欢
  • 1970-01-01
  • 2014-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-01
  • 2013-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多