You are absolutely right that after you add some library in the <script>
tag it becomes visible globally.
But since you use typescript with angular, you need to declare a variable representing this library entry point.
The reason is the typescript transpiller which has no idea about the fact you have added some libraries or any global variables.
By this line: declare var libr_name: any
you actually make transpiller to stop throwing an error during the build, because now libr_name
becomes a known variable.
If you face with such situation multiple times in your project, it probably would be nice to create separate globals.ts
file where you declare all global variables and reexport them. Then in other files you need to import globals.ts
.
globals.ts
declare var libr_name: any
declare var another_lib: any
export const globals = {
libr_name,
another_lib
}
any of your components .ts file
import {globals} from 'globals.ts'
// .... components code or whatever
globals.libr_name.do_stuff();
//....