简体   繁体   English

'google-chart' 不是已知元素:角度

[英]'google-chart' is not a known element: in angular

I am trying add google chart in angular app, I have done the following step我正在尝试在 Angular 应用程序中添加谷歌图表,我已经完成了以下步骤

  1. npm install angular-google-charts --save

  2. After that I have imported in to app module.之后,我已导入应用程序模块。

import { GoogleChartsModule } from 'angular-google-charts';
@NgModule({
 imports: [
   GoogleChartsModule
 ],
})
export class AppModule {}
  1. Calling in myComponent.html调用 myComponent.html
<google-chart #chart [title]="title" [type]="type" [data]="data [columnNames]="columnNames" [options]="options" [width]="width [height]="height">
</google-chart>
  1. In my component.ts在我的 component.ts
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';  
import { GoogleChartComponent } from 'angular-google-charts';  
  
@Component({  
  selector: 'app-root',  
  templateUrl: './app.component.html',  
  styleUrls: ['./app.component.scss']  
})  
export class AppComponent implements OnInit{  
  title = 'googlechart';  
  type = 'PieChart';  
  data = [  
     ['Name1', 5.0],  
     ['Name2', 36.8],  
     ['Name3', 42.8],  
     ['Name4', 18.5],  
     ['Name5', 16.2]  
  ];  
  columnNames = ['Name', 'Percentage'];  
  options = {      
  };  
  width = 500;  
  height = 300;  
  constructor(){}  
  ngOnInit() {}  
}

Error :错误 :

error NG8001: 'google-chart' is not a known element:
1. If 'google-chart' is an Angular component, then verify that it is part of this module.    
2. If 'google-chart' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

Component was exported on the library.组件已导出到库中。 https://github.com/FERNman/angular-google-charts/blob/master/libs/angular-google-charts/src/lib/google-charts.module.ts#L13 https://github.com/FERNman/angular-google-charts/blob/master/libs/angular-google-charts/src/lib/google-charts.module.ts#L13

You can use schemas: [ CUSTOM_ELEMENTS_SCHEMA ]您可以使用schemas: [ CUSTOM_ELEMENTS_SCHEMA ]

import { GoogleChartsModule } from 'angular-google-charts';
@NgModule({
 imports: [
   GoogleChartsModule
 ],
 schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppModule {}

This will fix the issue.这将解决问题。

I managed to solve the problem by putting it in shared.module.ts .我设法通过将其放入 shared.module.ts来解决问题。

And not in the AppModule as indicated.而不是在所示的 AppModule 中。

Olá, consegui resolver o problema colocando-o em shared.module.ts . Olá,consegui resolver o problema colocando-o em shared.module.ts

E não no AppModule conforme indicado. E não no AppModule conforme indicado。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM