Download object as file in AngularJS

1

Good evening! I am creating a component in Angular, to which I pass a text in a certain format and convert it to JSON format. So far so good. The point is that now I want to press a button, I downloaded the previously created object as a JSON file, and as much as I looked I can not find the form. Here I leave the part of the TS code where I create the object in JSON format:

> onSubmit(){
>     this.stats = this.FIFAstatsform.get('fifastats').value;
>     this.stats = this.stats.replace(/\n/g, " ");
>     this.statsplitted = this.stats.split(" ", 58);
>     this.jsonobject = '{';
>     for (let stat of this.statsplitted){
>       if (this.statsplitted.indexOf(stat)%2==0){
>         this.jsonobject=this.jsonobject+'"'+stat+'"'+':';
>       }
>       if (this.statsplitted.indexOf(stat)%2!=0 && this.statsplitted.length-1 != this.statsplitted.indexOf(stat)){
>         this.jsonobject=this.jsonobject+stat+',';
>       }
>       if (this.statsplitted.indexOf(stat)%2!=0 && this.statsplitted.length-1 == this.statsplitted.indexOf(stat)){
>         this.jsonobject=this.jsonobject+stat+'}';
>       }
>     }
>     this.creado = true;
    
asked by Álvaro Jiménez 27.12.2017 в 02:42
source

0 answers