How Import JS File in angular 6?

前端 未结 4 1408
忘了有多久
忘了有多久 2021-02-10 09:30

how can I import a js file in angular 6. I tried to implement a navbar and it contains js functions. thanks!!!

I Add my js file called nav.js

 \"scripts         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-10 09:55

    You should include on index.html, e.g:

    
    
    
      
       A random project
       
    
       
       
    
    
       
    
    
    
    
    
    

    On this case I included cartodb.js library, then for use cartodb.js on any component, or service I use:

    declare var cartodb: any;
    

    At the beginning of any file (Component, Service, etc).

    Note change cartodb by the name of the library you will use, for example for jquery is:

    declare var jquery:any;
    declare var $ :any;
    

    You should have something like this:

    import { Injectable } from '@angular/core';
    // Other imports...
    
    declare var cartodb: any;
    @Injectable()
    export class ARandomService {
    }
    

    P.s Search if the code you want to use doesn't exist in npm.

提交回复
热议问题