简体   繁体   中英

Inserting JavaScript inside components in Angular

I would like to insert a <script>...</script> inside a .html component in an Angular project and I was wondering how it can be done.

It seems like any Javascript I insert into this component is just ignored.

Yeah sure you can add javascript in Angular.You can make one external Javascript file and put all your code inside that file.For example you file is external.js in /app folder.And now you can access that file functions in Angular component.This is the easiest way I found. You can use import to include your external file. Code for that will be following.

import './external.js';
declare var myExtObject: any;

Now use one variable here I named myExtObject to call External.js file function like following any where you want :

myExtObject.func1();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM