admin管理员组

文章数量:1297123

I'm integrating a pure javascript library(materialize.js) with my angular typescript app. While activating the sidenav, I need to use the code.

M.Sidenav.init(document.querySelector('.sidenav'), [])

This works, and the sidenav is initiated, however, since I didn't define any M anywhere in the typescript file, the angular piler raises an error

ERROR in src/app/appponent.ts(34,5): error TS2304: Cannot find name 'M'.

Is there any way I can make typescript ignore this error, or in any way, fix it?

I'm integrating a pure javascript library(materialize.js) with my angular typescript app. While activating the sidenav, I need to use the code.

M.Sidenav.init(document.querySelector('.sidenav'), [])

This works, and the sidenav is initiated, however, since I didn't define any M anywhere in the typescript file, the angular piler raises an error

ERROR in src/app/app.ponent.ts(34,5): error TS2304: Cannot find name 'M'.

Is there any way I can make typescript ignore this error, or in any way, fix it?

Share Improve this question asked Nov 4, 2018 at 3:29 Dustbin Saves youDustbin Saves you 1261 silver badge8 bronze badges 3
  • what is M suppose to be? if M is materialize.js, you will need to import it using require()/import – Mox Commented Nov 4, 2018 at 3:31
  • use 'declare const M'; Also make sure library script file is included and imported. – Suresh Kumar Ariya Commented Nov 4, 2018 at 4:23
  • Thanks! I using 'declare const M' solved the problem – Dustbin Saves you Commented Nov 8, 2018 at 8:20
Add a ment  | 

1 Answer 1

Reset to default 9

You can follow these steps

npm install --save materialize-css 

npm install --save @types/materialize-css

declare const M;

import { SideNav } from "materialize-css";

本文标签: javascriptHow to ignore quotCannot find name 39M39 quot error in typescriptStack Overflow