Is it possible to write data to a locally json file with nothing but angular?

后端 未结 5 534
不思量自难忘°
不思量自难忘° 2020-12-03 04:44

I\'m trying to write data to a json file after hitting \"Submit\" on an html formly-form using only angular, but nothing is happening. I know I can read a json file using an

5条回答
  •  有刺的猬
    2020-12-03 05:23

    The following code adds a download button for a JSON object.

    Note: wrapping a button with an anchor tag is not recommended for HTML 5 yet it works in Chrome which is all I needed. YMMV.

    HTML:

    
      
    
    

    Typescript:

      get dataUri(): SafeUrl {
        const jsonData = JSON.stringify(this.dataSource);
        const uri = 'data:application/json;charset=UTF-8,' + encodeURIComponent(jsonData);
        return this.sanitizer.bypassSecurityTrustUrl(uri);
      }
    

提交回复
热议问题