In order to make all the promises in my Angular 8 project cancelable, I embarked on a quest to find the perfect library for the job. It was during this search that I stumbled upon bluebird.js, a promising candidate ;-)
Following these guidelines on integrating bluebird with Angular's zone-aware promises, I set out to include the necessary libraries as source files in my index.html
. To achieve this, I made the following adjustments in my angular.json
:
"assets": [
"src/favicon.ico",
"src/assets",
{
"glob": "**/*",
"input": "./node_modules/zone.js",
"output": "./assets/zone.js/"
},
{
"glob": "**/*",
"input": "./node_modules/bluebird",
"output": "./assets/bluebird/"
}
]
I then added the following script references in my index.html
:
<script src="/assets/zone.js/dist/zone.js"></script>
<script src="/assets/bluebird/js/browser/bluebird.js"></script>
<script src="/assets/zone.js/dist/zone-bluebird.js"></script>
<script>
Zone[Zone['__symbol__']('bluebird')](Promise);
Promise.config({cancellation: true});
</script>
Unfortunately, despite my efforts, I encountered an error stating
Uncaught TypeError: Bluebird.onPossiblyUnhandledRejection is not a function
.
Even when attempting to move the code from my index.html
to my main.ts
, the same error persisted.
In a final attempt, I modified the code in my main.ts
as follows:
import { Promise as Bluebird } from 'bluebird';
import 'zone.js/dist/zone-bluebird';
declare var Zone: any;
Zone[Zone['__symbol__']('bluebird')](Bluebird);
Bluebird.config({cancellation: true});
Alas, this alteration led to the error message
Zone.js has detected that ZoneAwarePromise (window|global) Promise has been overwritten.
Is there a way to successfully achieve this goal with the current versions of Angular and zone.js? Any suggestions would be greatly appreciated!