alferov/angular-file-saver

Angular Factory error when running in IE9 with Angular 1.4.1

Closed this issue · 1 comments

The SaveAs factory is erroring in IE9 with the following error:
"[$injector:undef] Provider 'SaveAs' must return a value from $get factory method.

Angular needs an something returned from the factory method.

The SaveAs function checks for browser <=IE9 and returns empty if the browser is unsupported. I changed this to return an "error" object: return {error: "Unsupported"};

This solves the issue and allows the file to load in IE <= 9.

Functions will need to test for IE9 support on their own to avoid erroring in IE

@lvanderbijl, @holm, I guess I found the simplest solution: returning an empty function if saveAs is undefined. It doesn't crash in IE9. However, it doesn't work in IE8 as angular team dropped IE8 support.
I'm not sure what is the best way to handle it after, though. Console.error an error message? :D
Return null instead of undefined, maybe?

return require('FileSaver.js').saveAs || function() { return null; };