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?
This is the code I want to use:
**$(document).ready(function(){
$('.sidenav').sidenav();
});**
Step-1: Created a js folder inside the assets folder.
Step-2: Created a new .js file inside the js folder. Assets -> js -> example.js
Step-3: Added path of the example.js in angular.json inside the scripts array.
Step-4: Declared the js function created in example.js inside the component.ts file where that function is needed.
Step-5: Made a call to the declared function inside ngOnInIt().
npm install jquery
npm install materialize-css@next
npm install --save @types/materialize-css @types/jquery
angular.json
and findscripts
fieldnode_modules/jquery/dist/jquery.min.js
andnode_modules/materialize-css/dist/js/materialize.min.js
inside array:declare var jQuery: any;
Example
You can use that inside
ngOnInit
.Find and open
angular.json
, then add toprojects.architect.build.options
object next field and change filepath to your own:Angular will add those custom files to result build