如何在 Angular 7 中使用 JavaScript 代码? [英] How can I use JavaScript code in Angular 7?

查看:26
本文介绍了如何在 Angular 7 中使用 JavaScript 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在移动屏幕上使用时,我试图在 MaterializeCSS 的帮助下制作一个可折叠的导航栏,并且需要在其中使用 JavaScript 代码.我应该在哪里编写这段 JavaScript 代码?

I'm trying to make a collapsible navbar with the help of MaterializeCSS when used on mobile screen and need to use JavaScript code in it. Where should I write this JavaScript code?

这是我要使用的代码:

**$(document).ready(function(){
    $('.sidenav').sidenav();
  });**

推荐答案

Step-1: 在 assets 文件夹中创建一个 js 文件夹.

Step-1: Created a js folder inside the assets folder.

第 2 步:在 js 文件夹中创建一个新的 .js 文件.资产 -> js -> example.js

Step-2: Created a new .js file inside the js folder. Assets -> js -> example.js

步骤 3:在脚本数组内的 angular.json 中添加 example.js 的路径.

Step-3: Added path of the example.js in angular.json inside the scripts array.

第 4 步:在需要该函数的 component.ts 文件中声明在 example.js 中创建的 js 函数.

Step-4: Declared the js function created in example.js inside the component.ts file where that function is needed.

第 5 步:调用 ngOnInIt() 中声明的函数.

Step-5: Made a call to the declared function inside ngOnInIt().

这篇关于如何在 Angular 7 中使用 JavaScript 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆