如何将新的矩阵化css 1.0 alpha版本导入angular 4

如何将新的矩阵化css 1.0 alpha版本导入angular 4,angular,typescript,materialize,Angular,Typescript,Materialize,需要将新的矩阵化css 1.0 alpha版本导入angular 4。我可以写下面的代码使事情顺利进行 <a onclick="M.toast({html: 'I am a toast'})" class="btn">Toast!</a> 我在.angular-cli.json中添加了脚本文件路径 "styles": [ "styles.css", "../node_modules/materialize-css/dist/css/materialize

需要将新的矩阵化css 1.0 alpha版本导入angular 4。我可以写下面的代码使事情顺利进行

<a onclick="M.toast({html: 'I am a toast'})" class="btn">Toast!</a>
我在.angular-cli.json中添加了脚本文件路径

"styles": [
    "styles.css",
    "../node_modules/materialize-css/dist/css/materialize.min.css"
  ],
  "scripts": [
    "../node_modules/materialize-css/dist/js/materialize.min.js"
  ]

我怎么能这样做呢。在这方面需要帮助,或者有任何其他方法可以让它工作。

这不是它的工作方式

首先,您需要在index.html文件中添加JS导入,并在angle-cli.json文件中将库声明为资产

你应该做后者。必须将脚本放入angular cli文件的“脚本”属性中

完成后,在组件中,您需要声明一个全局变量

declare var M: any;
现在在您的组件中,您将可以访问这个变量,就像在JS中一样

如果您有任何问题,请随时提问

详细编辑

angular-cli.json

在您的组件中


谢谢,谢谢ans。但是我到底需要在哪里添加declare var M:any;。我对node js和angular是全新的。所以,请帮助我。从“@angular/core”导入{Component,OnInit};声明var M:任何@组件{selector:'app login',templateUrl:'./login.Component.html',styleURL:['./login.Component.css']}导出类LoginComponent实现了OnInit{constructor{}ngOnInit test{M.toast{html:'I am a toast!',类:'rounded'};}在html中我添加了如下内容:toast!您是否已将其添加到angular cli文件中?是的,我已添加。请查看我提到的qus描述。好吧,这是一个愚蠢的问题,但我们永远不知道:这个包在你的package.json文件中吗?
declare var M: any;
"styles": [
  "You should have some styles in this property",
  "Add your dependency like so"
  "../node_modules/PATH/TO/MATERIALIZE.css"
],
"scripts": [
  "You should have some scripts in this property",
  "Add your dependency like so"
  "../node_modules/PATH/TO/MATERIALIZE.js"
],
// First, you have your import zone
import { ... } from '...';

// You put your declare here
declare var M: any;

// Then you have the component
@Component({...})
export class MyComponent implements onInit { ... }