How To Use JavaScript Function In Angular Application

Introduction

In this article, we will learn about how to use JavaScript function in Angular Applications. We can better understand this step by step.

Step 1

Create Angular Application with the use of following command

ng new javascriptfunctionuseAngularApp

Step 2

Create one Javascript file inside App Folder

How to Use JavaScript Function in Angular Application.

Step 3

Write one Function in Javascriptfun.js file like this

EXPORTS keyword is used to write any function it can use in typescript file,

exports.callJSFun=function(){
    console.log("Hello Call JS Function From TypeScript ");
}

Step 4

Call function in Typescript File Like

1. inside AppComponent add ngOnInit() method inside Call Javascript function like this 

How to Use JavaScript Function in Angular Application.

2. Import javascript file. ( import {callJSFun} from '../app/javascriptfun.js'; )

How to Use JavaScript Function in Angular Application.

Could not find a declaration file for module '../app/javascriptfun.js'. 'd:/bhavesh/ddd/demo/javascriptfunctiondemo/src/app/javascriptfun.js' implicitly has an 'any' type.ts(7016)

View Problem Error so it can be resolved in the next step.

3. If you don't like this behavior and want to suppress errors when values are implicitly typed as any, set the noImplicitAny option to false in your tsconfig.json file.

How to Use JavaScript Function in Angular Application.

Error is resolved and Javascript function is called in console like 

How to Use JavaScript Function in Angular Application.

Conclusion

Nowadays some applications require the JavaScipt function. So this article is very helpful for calling the JavaScript function 

Enjoy Coding !!!!

We have got the response. Fantastic! The JavaScript function used in Angular Application is working as expected.

Thank you for reading my article. Please leave your comments in the comment box below.


Similar Articles