Using @ types / angular as global

I'm currently trying to upgrade my angular 1 app from typings to @types .

First I received the following error message:

 Identifier 'angular' must be imported from a module 

After some searching, I found out that angular is no longer available globally. Or at least I didn’t find out how ...


With typings , angular was global, and I could use it without importing or anything else. My problem is that the import is angular, for example:

 import * as angular from 'angular'; 

breaks my application: Unfortunately, SystemJS now trying to load angular, and because of this, it is not available when ui-bootstrap and other libraries are loaded with script tags.

To fix this, I would have to rewrite a huge part of the build pipeline. So I ask again: is there another way to use angular with TypeScript 2 and @types that doesn't end with require('angular') ?

+5
source share
1 answer

I have found the answer. Do this and everything will work finr.

 import * as _angular_ from 'angular'; declare global { const angular: typeof _angular_; } 
+3
source

Source: https://habr.com/ru/post/1260133/


All Articles