Collectives on Stack Overflow. Learn more. Asked 6 years, 9 months ago. Active 4 years, 8 months ago. Viewed 56k times. Improve this question. Add a comment. Active Oldest Votes. Happy Coding!!! URL window. Improve this answer. Sagar Desai Sagar Desai 1 1 gold badge 3 3 silver badges 11 11 bronze badges.
We will achieve this using our custom written functions and using the download attribute of HTML 5. The download attribute in HTML 5 is used to download files when users click on the hyperlink. We are required to set the href attribute specifying the source of the file. The value of the download attribute determines the name of the downloaded file. If this value is removed, then the downloaded filename will be the same as the original file name. In the above code, we download an image apple.
When the service is provided at root level, Angular creates a single, shared instance of service and injects into any class that needs it. Registering the provider in the Injectable metadata also allows Angular to optimize an application by removing the service if it is not used. If you are not using stricter type then your code should be working fine as it is working for Angular First replace the line this.
I am also accepting response as Blob Binary Large Object. You may also specify any value from supporting values, such as, json, blob, arraybuffer, text. You can have a look for more details on response type.
I have used three ways for downloading file — two ways for Save as functionality and one way to show the file content on browser itself. The above line create a Blob object with file content in response and expecting the file of JSON type. The above two lines create a URL that will open the file in browser in new window.
The above line shows the file content on browser, so it does not give you save as option. The above line uses ready-made FileSaver module that will open the file with Save as option. Email Required, but never shown. The Overflow Blog. Podcast An oral history of Stack Overflow — told by its founding team. Millinery on the Stack: Join us for Winter Summer?
Bash, ! Featured on Meta. New responsive Activity page. Visit chat. Linked 0. Related
0コメント