我想在我的项目中使用 Materialize CSS
框架。
我使用 Angular CLI
建立了一个项目 ng new BLABLA
之后,我按照 this 指南中的步骤操作。
但是,如果我使用 ng serve
启动项目,我会在浏览器中收到此错误:
TypeError: undefined is not an object (evaluating 'jQuery.easing.swing')
我的 angular-cli.json
{
"project": {
"version": "1.0.0-beta.15",
"name": "blabla"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": "assets",
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/materialize-css/dist/js/materialize.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { MaterializeModule } from 'angular2-materialize';
import "materialize-css";
import { AppComponent } from './app.component';
@NgModule({
declarations: [ AppComponent ],
imports: [
BrowserModule,
FormsModule,
HttpModule,
MaterializeModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
最佳答案
你需要做的是如下:
将此行添加到您的全局 css 文件中:
@import "../node_modules/materialize-css/dist/css/materialize.css";
并删除此行
导入“materialize-css”;
来自 app.module.ts
如果你在任何情况下运行它,也要确保你安装了正确的 jquery 版本:
npm install jquery@^2.2.4 --save
这样做对我有用。 [祝你好运]
关于angularjs - 如何在使用 angular cli 创建的项目中集成 angular2-materialize,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39675673/