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

查看:117
本文介绍了如何在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();
  });**

推荐答案

步骤1:在资产文件夹中创建了一个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步:在scripts数组内的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天全站免登陆