How use js library with jquery on angular2 (typescript)?

Mediator

I try migrate angular js to angularjs2 with typescript.

I can't understand how use js library. I have main app.component where I want initialize some library, for example simple row:

$('#home').height($(window).height());

and initialize by attribute data-spy="scroll" data-target="#header-navbar" data-offset="51"

Index.html

<body data-spy="scroll" data-target="#header-navbar" data-offset="51" class="pace-done">

    <pm-app>Loading App...</pm-app>


    <!-- ================== BEGIN BASE JS ================== -->
    <script src="assets/plugins/jquery/jquery-1.9.1.min.js"></script>
    <script src="assets/plugins/jquery/jquery-migrate-1.1.0.min.js"></script>
    <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
        <script src="assets/crossbrowserjs/html5shiv.js"></script>
        <script src="assets/crossbrowserjs/respond.min.js"></script>
        <script src="assets/crossbrowserjs/excanvas.min.js"></script>
    <![endif]-->
    <script src="assets/plugins/jquery-cookie/jquery.cookie.js"></script>
    <script src="assets/plugins/scrollMonitor/scrollMonitor.js"></script>
<script src="assets/js/landing-apps.js"></script>

    <!-- ================== BEGIN BASE JS ================== -->
      <script src="assets/plugins/pace/pace.min.js"></script>
    <!-- ================== END BASE JS ================== -->
<!-- ================== END BASE JS ================== -->
    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="node_modules/systemjs/dist/system-polyfills.js"></script>
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>

    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>


    <!-- Required for http -->
    <script src="node_modules/angular2/bundles/http.dev.js"></script>

    <!-- Required for routing -->
    <script src="node_modules/angular2/bundles/router.dev.js"></script>

    <!-- 2. Configure SystemJS -->
    <script>
        System.config({
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js'
                }
            }
        });
        System.import('app/main')
            .then(null, console.error.bind(console));
    </script>

</body>

general main.ts

import { bootstrap }    from 'angular2/platform/browser';

// Our main component
import { AppComponent } from './app.component';

bootstrap(AppComponent);

and empty app.component.

Pardeep Jain

In order to use jQuery you firstly you have to import in the index.html, than you can initialize your code in the constructor of component

constructor(){
   .....
   $('#home').height($(window).height());
}

in case IDE shows error than you can declare $ of any type at the top of the class like this :-

...some  code here 
declare var $ : any;

export class App{
..///code goes here
}

see also may help you

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to use moment.js library in angular 2 typescript app?

From Java

How to use a typescript enum value in an Angular2 ngSwitch statement

From Dev

How to use jQuery in TypeScript

From Dev

How to use Angular2 and Typescript in Jsfiddle

From Dev

use an input in class on angular2 with typescript

From Dev

How to check Angular2 version with typescript

From Dev

How typescript is converted to javascript in angular2?

From Dev

How to use js libraries with typescript?

From Dev

how to use underscore.js library in angular 2

From Dev

How to import and use a jQuery library via Webpack?

From Dev

How to include Third party javascript library in angular2 webpack typescript

From Dev

Typescript - how to correctly use jsPDF in Angular2?

From Dev

How to include Jquery/Bootstrap files into the stack Webpack/angular2/typescript

From Dev

Use JS library xml2js with Angular 2

From Dev

Typescript: How to reference jquery-easyui library?

From Dev

How to use jQuery in TypeScript

From Dev

How to use bootstrap/jquery in Angular2

From Dev

How to import and use a jQuery library via Webpack?

From Dev

Typescript - how to correctly use jsPDF in Angular2?

From Dev

How to include Jquery/Bootstrap files into the stack Webpack/angular2/typescript

From Dev

Use JS library xml2js with Angular 2

From Dev

Run plugin-typescript library from localhost in Angular2

From Dev

How to use Bootstrap css Library in Angular 2?

From Dev

How to use handsontable library in angular 2

From Dev

How can we use bootstrap-sweetalert library in angular2 or 4?

From Dev

How to bundle up a set of Typescript classes and use it in other angular2/typescript projects?

From Dev

how to use SlickGrid (jQuery legacy library) in Angular 4

From Dev

Use a pure JS library in Angular

From Dev

How to use thirdparty js library in Angular 2+ without installing types?

Related Related

  1. 1

    How to use moment.js library in angular 2 typescript app?

  2. 2

    How to use a typescript enum value in an Angular2 ngSwitch statement

  3. 3

    How to use jQuery in TypeScript

  4. 4

    How to use Angular2 and Typescript in Jsfiddle

  5. 5

    use an input in class on angular2 with typescript

  6. 6

    How to check Angular2 version with typescript

  7. 7

    How typescript is converted to javascript in angular2?

  8. 8

    How to use js libraries with typescript?

  9. 9

    how to use underscore.js library in angular 2

  10. 10

    How to import and use a jQuery library via Webpack?

  11. 11

    How to include Third party javascript library in angular2 webpack typescript

  12. 12

    Typescript - how to correctly use jsPDF in Angular2?

  13. 13

    How to include Jquery/Bootstrap files into the stack Webpack/angular2/typescript

  14. 14

    Use JS library xml2js with Angular 2

  15. 15

    Typescript: How to reference jquery-easyui library?

  16. 16

    How to use jQuery in TypeScript

  17. 17

    How to use bootstrap/jquery in Angular2

  18. 18

    How to import and use a jQuery library via Webpack?

  19. 19

    Typescript - how to correctly use jsPDF in Angular2?

  20. 20

    How to include Jquery/Bootstrap files into the stack Webpack/angular2/typescript

  21. 21

    Use JS library xml2js with Angular 2

  22. 22

    Run plugin-typescript library from localhost in Angular2

  23. 23

    How to use Bootstrap css Library in Angular 2?

  24. 24

    How to use handsontable library in angular 2

  25. 25

    How can we use bootstrap-sweetalert library in angular2 or 4?

  26. 26

    How to bundle up a set of Typescript classes and use it in other angular2/typescript projects?

  27. 27

    how to use SlickGrid (jQuery legacy library) in Angular 4

  28. 28

    Use a pure JS library in Angular

  29. 29

    How to use thirdparty js library in Angular 2+ without installing types?

HotTag

Archive