projects/ng2-google-charts/src/lib/google-charts-control/google-charts-control.component.ts
| selector | google-charts-control |
| template | |
Properties |
|
Methods |
|
Inputs |
Public
constructor(el: ElementRef, loaderService: GoogleChartsLoaderService)
|
|||||||||
|
Parameters :
|
| data | |
Type : GoogleChartsControlInterface
|
|
| Public Async ensureInit |
ensureInit()
|
|
Returns :
any
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| Public wrapper |
Type : any
|
declare var google: any;
export interface GoogleChartsControlInterface {
controlType: string;
options?: object;
state?: object;
component?: GoogleChartsControlComponent;
}
import {
Component, OnInit, Input,
ElementRef
} from '@angular/core';
import { GoogleChartsLoaderService } from '../google-charts-loader.service';
interface InternalGoogleChartsControlOptions extends GoogleChartsControlInterface {
containerId: string;
}
@Component({
selector: 'google-charts-control',
template: '<div></div>',
})
export class GoogleChartsControlComponent implements OnInit {
@Input() public data!: GoogleChartsControlInterface;
public wrapper: any;
public constructor(private el: ElementRef,
private loaderService: GoogleChartsLoaderService) {
this.el = el;
this.loaderService = loaderService;
}
ngOnInit() {
this.data.component = this;
}
public async ensureInit() {
if (this.wrapper) {
return;
}
await this.loaderService.load({packages: ['controls'] });
let opt: InternalGoogleChartsControlOptions;
opt = Object.create(this.data);
opt.containerId = this.el.nativeElement.querySelector('div');
this.wrapper = new google.visualization.ControlWrapper(opt);
}
}