Skip to content

docs(@angular/cli): Updates global library instructions #6339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions docs/documentation/stories/global-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ global library, and one imported as a module.
This is especially bad for libraries with plugins, like JQuery, because each copy will have
different plugins.

Instead, download typings for your library (`npm install @types/jquery`) which will give you
access to the global variables exposed by that library.
Instead, download typings for your library (`npm install @types/jquery`) and follow
the [3rd Party Library Installation](https://github.com/angular/angular-cli/wiki/stories-third-party-lib) steps,
this will give you access to the global variables exposed by that library.

If the global library you need to use does not have global typings, you can also declare them
manually in `src/typings.d.ts` as `any`:

```
declare var libraryName: any;
```
```

When working with scripts that extend other libraries, for instance with JQuery plugins
(e.g, `$('.test').myPlugin();`), since the installed `@types/jquery` may not include `myPlugin`,
you would need to add an interface like the one below in `src/typings.d.ts`.

```
interface JQuery {
myPlugin(options?: any): any;
}
```

Otherwise you may see `[TS][Error] Property 'myPlugin' does not exist on type 'JQuery'.` in your IDE.