Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { Forecast } from '../../forecast';
- import { ForecastService } from '../../forecast.service';
- import { DynamicScriptLoaderService } from '../../dynamic-script-loader-service.service';
- declare const $: any;
- @Component({
- selector: 'app-blank',
- templateUrl: './blank.component.html',
- styleUrls: ['./blank.component.scss']
- })
- export class BlankComponent implements OnInit {
- dados: any;
- forecast: Forecast = new Forecast();
- submitted = false;
- constructor(private forecastService: ForecastService, private dynamicScriptLoader: DynamicScriptLoaderService) { }
- ngOnInit() {
- // this.startScript()
- }
- async startScript(datas) {
- await this.dynamicScriptLoader.load('dataTables.buttons','buttons.flash','jszip','pdfmake','vfs_fonts','pdfmake','buttons.html5','buttons.print').then( data => {
- this.loadData(datas);
- console.log(datas);
- }).catch(error => console.log(error));
- }
- private loadData(dats){
- $('#tableExport').DataTable({
- "aaData": dats,
- dom: 'Bfrtip',
- buttons: [
- 'copy', 'csv', 'excel', 'pdf', 'print'
- ]
- });
- console.log(dats);
- }
- // async startScript() {
- // await this.dynamicScriptLoader.load('dataTables.buttons','buttons.flash','jszip','pdfmake','vfs_fonts','pdfmake','buttons.html5','buttons.print').then( data => {
- // this.loadData();
- // }).catch(error => console.log(error));
- // }
- //
- // private loadData(){
- // $('tableExport').DataTable({
- // "aaData": this.dados,
- // dom: 'Bfrtip',
- // buttons: [
- // 'copy', 'csv', 'excel', 'pdf', 'print'
- // ]
- // });
- // console.log(this.dados)
- // }
- newForecast(): void {
- // this.submitted = false;
- // this.forecast = new Forecast();
- }
- save() {
- this.forecastService.createForecast(this.forecast)
- .subscribe(
- data => {
- this.dados = JSON.parse(data);
- console.log(this.dados);
- this.startScript(this.dados);
- this.submitted = true;
- },
- error => console.log(error));
- this.forecast = new Forecast();
- }
- // save() {
- // this.forecastService.createForecast(this.forecast)
- // .subscribe(
- // data => {
- // //console.log(data);
- // //this.dados = JSON.stringify(data);
- // //this.dados = data.toString();
- // this.dados = JSON.parse(data);
- // console.log(this.dados.columns);
- // // console.log(this.dados.data);
- //
- // // this.loadData();
- // this.submitted = true;
- // },
- // error => console.log(error)
- // // checar se data é diferente de código de erro
- // // chamar newjuanito usando o bang da tabela
- // );
- // this.forecast = new Forecast();
- // }
- onSubmit() {
- this.save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement