typescript “ag-grid-angular”不是已知元素:

ix0qys7i  于 2022-12-24  发布在  TypeScript
关注(0)|答案(2)|浏览(169)

我已经使用ag-grid几个月了,今天,我尝试在这个Angular模板中集成一个我在以前的项目中成功构建的网格:
ngx-admin这是模板的外观:

我尝试在extra-components中添加另一个页面,其中包含网格:
但是,正如您所看到的,模板没有被渲染。
这是项目中的extra-components文件夹:

action-plan.component.html

<!-- I have tested this with a normal  Angular project and it worked perfectly -->
ahmed
<ag-grid-angular
style="width: 100% ; height: 1000px;"
[rowData]="actionPlanPartiesrowData"
[columnDefs]="actionPlanPartiescolumnDefs"
(gridReady)="actionPlanPartiesonGridReady($event)"
[getRowHeight]="getRowHeight"
[animateRows]="true"
[defaultColDef]="defaultColDef"
(cellValueChanged)="onactionPlanPartiesCellValueChanged($event)"
>
</ag-grid-angular>

action-plan.component.ts

import { Component, OnInit } from "@angular/core";

@Component({
  selector: "app-action-plan",
  templateUrl: "./action-plan.component.html",
  styleUrls: ["./action-plan.component.css"]
})
export class ActionPlanComponent implements OnInit {
  private actionPlangridApi;
  actionPlanPartiescolumnDefs = [
    {
      headerName: "Id",
      field: "id",
      editable: true,
      width: 100
    },
    {
      headerName: "Project",
      field: "project",
      editable: true,
      width: 400
    },
    {
      headerName: "Risk ID",
      field: "riskId",
      editable: true,
      width: 300
    },
    {
      headerName: "ISO 27001",
      field: "iso27001",
      editable: true,
      width: 150
    },
    {
      headerName: "Priority",
      field: "priority",
      editable: true,
      width: 150
    },
    {
      headerName: "Project Owner",
      field: "projectOwner",
      editable: true,
      width: 150
    },
    {
      headerName: "Estimated Cost",
      field: "estimatedCost",
      editable: true,
      width: 150
    }
  ];
  actionPlanPartiesrowData = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
  defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true
  };
  ngOnInit() {}
  constructor() {}
  actionPlanPartiesonGridReady(params) {
  }
  onactionPlanPartiesCellValueChanged(params) {
  }

  public getRowHeight(params) {
    return 130;
  }
}

extra-components.module.ts

import { NgModule } from '@angular/core';

import { TreeModule } from 'angular-tree-component';
import { ToasterModule } from 'angular2-toaster';

import { ThemeModule } from '../../@theme/theme.module';
import { ExtraComponentsRoutingModule } from './extra-components-routing.module';

// components
import { ExtraComponentsComponent } from './extra-components.component';
import { TreeComponent } from './tree/tree.component';
import { SpinnerInTabsComponent } from './spinner/spinner-in-tabs/spinner-in-tabs.component';
import { SpinnerInButtonsComponent } from './spinner/spinner-in-buttons/spinner-in-buttons.component';
import { SpinnerSizesComponent } from './spinner/spinner-sizes/spinner-sizes.component';
import { SpinnerColorComponent } from './spinner/spinner-color/spinner-color.component';
import { SpinnerComponent } from './spinner/spinner.component';
import {
  InteractiveProgressBarComponent,
} from './progress-bar/interactive-progress-bar/interactive-progress-bar.component';
import { ProgressBarComponent } from './progress-bar/progress-bar.component';
import { AlertComponent } from './alert/alert.component';
import { ChatComponent } from './chat/chat.component';
import { Tab1Component, Tab2Component, TabsComponent } from './tabs/tabs.component';
import { CalendarComponent } from './calendar/calendar.component';
import { DayCellComponent } from './calendar/day-cell/day-cell.component';
import { StepperComponent } from './stepper/stepper.component';
import { ListComponent } from './list/list.component';
import { InfiniteListComponent } from './infinite-list/infinite-list.component';
import { NewsPostComponent } from './infinite-list/news-post/news-post.component';
import { NewsPostPlaceholderComponent } from './infinite-list/news-post-placeholder/news-post-placeholder.component';
import { AccordionComponent } from './accordion/accordion.component';
import { NebularFormInputsComponent } from './form-inputs/nebular-form-inputs.component';
import { NebularSelectComponent } from './form-inputs/nebular-select/nebular-select.component';
import { CalendarKitFullCalendarShowcaseComponent } from './calendar-kit/calendar-kit.component';
import { CalendarKitMonthCellComponent } from './calendar-kit/month-cell/month-cell.component';

// service
import { NewsService } from './services/news.service';

import { ActionPlanComponent } from './ahmed/action-plan.component';
import { AgGridModule } from 'ag-grid-angular';

const COMPONENTS = [
  ExtraComponentsComponent,
  TreeComponent,
  AlertComponent,
  ProgressBarComponent,
  InteractiveProgressBarComponent,
  SpinnerComponent,
  SpinnerColorComponent,
  SpinnerSizesComponent,
  SpinnerInButtonsComponent,
  SpinnerInTabsComponent,
  CalendarComponent,
  DayCellComponent,
  ChatComponent,
  TabsComponent,
  Tab1Component,
  Tab2Component,
  StepperComponent,
  ListComponent,
  InfiniteListComponent,
  NewsPostComponent,
  NewsPostPlaceholderComponent,
  AccordionComponent,
  NebularFormInputsComponent,
  NebularSelectComponent,
  CalendarKitFullCalendarShowcaseComponent,
  CalendarKitMonthCellComponent,
  ActionPlanComponent
];

const SERVICES = [
  NewsService,
];

const MODULES = [

];

@NgModule({
  imports: [
    ThemeModule,
    ExtraComponentsRoutingModule,
    TreeModule,
    ToasterModule.forRoot(),
    AgGridModule.withComponents([

    ])
  ],
  declarations: [
    ...COMPONENTS,
  ],
  providers: [
    ...SERVICES,
  ],
})
export class ExtraComponentsModule { }

其他人也遇到过和我一样的问题,但提供的解决方案是将ag-grid-angular导入到app. module. ts中,我也这么做了。但是,这并没有解决问题。(在我的例子中,extra-components. module. ts)在项目中的更高级别的文件夹中还有其他module. ts文件,我也在其中导入了ag-grid-angular模块,以防万一:


下面是VSCode中显示的内容:
"ag-grid-angular"不是已知元素:1.如果"ag-grid-angular"是Angular 分量,然后验证它是否是此模块的一部分。2.如果"ag-grid-angular"是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到此组件的"@NgModule. schemas "以禁止显示此消息。Angular 无法绑定到" getRowHeight ",因为它不是" ag-grid-angular "的已知属性。1.如果" ag-grid-angular "是一个Angular 分量,并且具有"getRowHeight"输入,然后验证它是否是此模块的一部分。2.如果"ag-grid-angular"是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到此组件的"@NgModule. schemas "中以禁止显示此消息。3.要允许任何属性,请将" NO_ERRORS_SCHEMA "添加到此组件的"@NgModule. schemas"中。Angular

9bfwbjaz

9bfwbjaz1#

这是一个小的修复。如果您已经按照https://www.ag-grid.com/angular-grid/#add-ag-grid-to-your-project中的过程操作,则导入BrowserAnimationsModuleFormsModule将解决此问题。

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';

@NgModule({
  declarations: [
AppComponent
  ],
  imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
AgGridModule.withComponents([]),
AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
f87krz0w

f87krz0w2#

在我的例子中,问题是关于tsconfig.json中的类型数组。
我在jest的帮助下做单元测试,因为jest已经输入了jest类型。
当我在数组中添加节点时,它开始接受ag-grid-angular元素。
修复tsconfig.json文件之前:-

"types": ["jest"]

修复后:-

"types": ["node","jest"]

相关问题