0
votes

I am having an issue with my new Angular CLI project (version information below). It appears that the extension of the window object no longer works in the new version.

ng --version angular-cli: 1.0.0-beta.17 node: 6.9.1 os: win32 x64 windows 10

I have a myAPI.js file that looks like this...

var myAPI = myAPI || {};  

(function(myAPI) {
...
...
}(myAPI));

window.myAPI = myAPI;

I have a myAPI.d.ts file that has this interface defined in it (nothing else).

interface Window {
myAPI: any;
}

In my Typescript code i used to be able to write window.myAPI.XXX and it would work fine, i recently updated to the above version and it's not working anymore.

The error message is that window.myAPI is undefined.

This was the ng --version details from the version where this was previously working.

angular-cli: 1.0.0-beta.10 node: 6.3.0 os: win32 x64

Has something changed that stops this sort of thing from working between 1.0.0-beta.10 and 1.0.0-beta.17?

1

1 Answers

0
votes

The issue was this:

Due to the modularization introduced with the newer version it was not bootstrapping the "myAPI.d.ts" file that had the interface defined in it.

In order to resolve this, the interface definition needed to be added to a module, component or service that was then imported and declared in "app.module.ts".

Once this was in place it worked as expected.