How to import jQuery to Angular2 TypeScript projects?

前端 未结 7 1924
一向
一向 2020-12-01 14:48

I want to wrap some jQuery code in an Angular2 directive.

I installed jQuery library for Typings into my project with the following command:

typings in

7条回答
  •  爱一瞬间的悲伤
    2020-12-01 15:21

    Step 1: get jquery in your project

    npm install jquery
    

    Step 2: add type for jquery

    npm install -D @types/jquery
    

    Step 3: Use it in your component!

    import * as $ from 'jquery';
    

    Ready to use $!

提交回复
热议问题