Angular include CDN in component usage | angular 7 cdn
Ifyouwantuserstoretrievethejs/cssfilesfromaCDN,youneedtoincludethesefilesinyourindex.html.Examplewithmomentjs(Note:thisisjustanexample,momentjscanbeinstalledvianpminyourproject)index.html
If you want users to retrieve the js/css files from a CDN, you need to include these files in your index.html. Example with momentjs (Note: this is just an example, momentjs can be installed via npm in your project)
index.html
<!-- get script from CDN --> <script src="https://i1.wp.com/cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js" />Then, to use the the script in your component, you need to manually declare the exported variables / functions to avoid TS compilation errors
component.ts
declare let moment: any; //declare moment //use moment moment().format(....);Note: some libraries have types that you can use instead, instead of using any. You can get these types from the @types repository