3

i am new to angular 4. i am calling a jquery function with html tag from a method. And that jquery method is defined in another file. so how to write those in angular? this is the example

sample() {
  $.("represent-visualization").Sample();
}

And the function Sample is defined in a jquery file

(function( $ ){
   $.fn.sample()
    {
     }
 })(jquery);
3
  • take a look at this link how to add external js in Angular with or wothout typings Commented Sep 22, 2017 at 7:56
  • What are you trying to do? You shouldn't need to use jQuery within Angular, please provide more of your code. Commented Sep 22, 2017 at 8:27
  • instead of using jquery how can i use this by using simple functions? Commented Sep 22, 2017 at 9:30

1 Answer 1

1
npm install jquery --save


npm install --save-dev @types/jquery

Install jquery with npm

npm install jquery --save

Add typings

npm install --save-dev @types/jquery

Add scripts to angular-cli.json

when you cant to import

import * as jquery from "jquery";

jquery.("represent-visualization").Sample();

Sign up to request clarification or add additional context in comments.

1 Comment

still i am not getting .. its giving an error saying some identifier is expected ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.